0
无法更新数据,错误而Laravel
控制器代码更新数据
public function update(Request $request, $id)
{
//
echo $request->all();
/* $user= User::find($id);
$user->update($request->all());
$user->save();
return redirect('user');*/
}
数据不会得到更新,这就是为什么使用的回声。
当使用
echo $request->all(); (line 86)
得到了错误
(1/1) ErrorException
Array to string conversion
in userController.php (line 86)
使用
dd($request->all());
了导致
array:14 [▼
"_method" => "PUT"
"_token" => "zDkzEpJCKscUgAGvgFQwu6gKbtRwm8N8MdBHC9em"
"userType" => "Admin"
"firstName" => "Sda"
"lastName" => "ad"
"gender" => "M"
"personalContact" => "123"
"officeContact" => "132"
"email" => "ads"
"country" => "ds"
"state" => "ds"
"city" => "ddsf"
"address" => "dsf"
"zipCode" => "1234"
]
我的模型
class User extends Model
{
//
protected $fillable = [
'userType', 'firstName', 'lastName', 'gender','personalContact','officeContact','email','country','state','city','address','zipCode'
];
/* public $incrementing = false;*/
}
用户表迁移
Schema::create('users', function (Blueprint $table) {
$table->increments('Id');
$table->uuid('userType');
$table->string('firstName');
$table->string('lastName');
$table->char('gender');
$table->string('personalContact');
$table->string('officeContact');
$table->string('email');
$table->uuid('country');
$table->uuid('state');
$table->uuid('city');
$table->string('address');
$table->integer('zipCode');
$table->rememberToken();
$table->timestamps();
});
任何人都可以请让我知道,我做了什么错
但存储方法使用相同&其工作正常 – Sumeet
您的用户模型是否具有$ fillable或$ guarded属性集?如果是这样,他们需要与您传递给update()方法的内容对齐。如果您愿意,请发布您的使用模型类。 – btl
我一直在保护$ fillable ='userType','firstName','lastName','gender','personalContact','officeContact','email','country','state','city', 'address','zipCode' ]; – Sumeet