【发布时间】:2021-04-16 04:23:03
【问题描述】:
我正在 Laravel 中创建一个小型测试网络商店。试图编辑用户配置文件。有这么多领域:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('phone')->nullable();
$table->string('img')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
但是我尝试只更改其中的3个,并显示错误,其他人没有默认值,为什么它甚至会触及其他字段?还是我做错了什么?
public function user_edit(Request $request, User $user){
$user->name = $request->name?$request->name:Auth::user()->name;
$user->email = $request->email?$request->email:Auth::user()->email;
$user->phone = $request->phone?$request->phone:(Auth::user()->phone?Auth::user()->phone:NULL);
$user->save();
return redirect()->back();
}
【问题讨论】: