//in model
protected $fillable1 = [
'id', 'email','name', 'phone',
];//for create
protected $fillable2 = [
'name', 'phone'
];//for update
//in controler
public function store
User::create($request->all());
public function update
User::findOrFail($user_id)->fill($request->all())->save();
因此在此示例列中,电子邮件将是可创建但不可编辑的
User::create($request->all());
User::create($request->$fillable1());
和
User::findOrFail($user_id)->fill($request->all())->save();
User::findOrFail($user_id)->fill($request->$fillable2())->save();
答案 0 :(得分:1)
$fillable
由Model使用,因此,您将需要一个变量 $ fillable 。
尝试使用此:
protected $hidden = [
'email', 'password',
];
或只需修改您的控制器即可仅更新您想要的内容:)
User::findOrFail($user_id)->fill(['values_here'])->save();