小编krs*_*ndm的帖子

Laravel Form-Model Binding多选默认值

我正在尝试将默认值绑定到选择标记.(在"编辑视图"中).

我知道这应该很容易,但我想我错过了一些东西.

我有:

User.php(我的用户模型)

...
    public function groups() 
{
    return $this->belongsToMany('App\Group');
}

public function getGroupListAttribute()
{
    return $this->groups->lists('id');
}
...
Run Code Online (Sandbox Code Playgroud)

UserController.php(我的控制器)

...
public function edit(User $user)
{
    $groups = Group::lists('name', 'id');

    return view('users.admin.edit', compact('user', 'groups'));
}
...
Run Code Online (Sandbox Code Playgroud)

edit.blade.php(视图)

...
{!! Form::model($user, ['method' => 'PATCH', 'action' => ['UserController@update', $user->id]]) !!}
...

...
// the form should be binded by the attribute 'group_list' created
// at the second block of 'User.php'
// performing a $user->group_list gets me the correct …
Run Code Online (Sandbox Code Playgroud)

html php binding laravel blade

11
推荐指数
1
解决办法
1995
查看次数

标签 统计

binding ×1

blade ×1

html ×1

laravel ×1

php ×1