方案一:
在 UserRequest 中想办法
protected $create = [
'email'=> 'required|unique:users',
'name'=> 'required',
...
];
protected $update = [
'name'=> 'required',
...
];
public function rules()
{
if ($this->isMethod('get')) return [];
if ($this->is('*/create')) return $this->create;
else if ($this->is('*/update')) return $this->update;
else return [];
}
方案二:
在 UserController 中想办法
public function update(Request $request)
{
$form_data = $request->except(['_token', 'email']);
$user = User::where('email', $request->email)->first();
$user->fill($form_data);
$user->save();
}
方案三:
在 update 视图中想办法
<form action="{ route('update') }" method="POST">
Email: <input type="text" name="email" value="{ $user->email }" disabled>
Name: <input type="text" name="name" value="{ $user->name }">
...
</form>