users【用户表】
users表中只存了用户名,手机号,密码
++++++++++++++++++++++++++++++++++
user_profile【用户信息表】
性别,头像,认证信息之类的字段都存到此表
后台编辑用户的时候,提交后
public function update(Request $request, $id)
{
$this->validate($request, [
'name' => 'required|min:3|max:20',
'phone' => 'required|digits:11|unique:users,phone,' . $id,
]);
$user = User::find($id);
$data = $request->all();
if($request->password) {
$data['password'] = Hash::make($request->password);
} else {
$data['password'] = $user->password;
}
if ($request->file) {
$validate = ImageHelper::validate($request->file, 2000000);
if (!$validate['success']) {
return redirect()->back()->with('error', $validate['message']);
}
$image = ImageHelper::create($request->file, 600, 'admin/images/users/');
$data['image'] = $image['filename'];
}
$user->update($data);
$user->UserProfile()->update($data);
return redirect()->route('admin::users.index')->with('success', 'User successfully updated');
}
关联模型中是这样写的
public function userProfile()
{
return $this->hasOne('App\UserProfile', 'user_id', 'id');
}
更新的时候报错
QueryException in Connection.php line 655:
SQLSTATE[42S22]:
Column not found: 1054 Unknown column '_token' in 'field list' (SQL:
update `s_user_profile` set `_token` =
2Apiil1kSDOeNzNendwjcuRj4lJTDjb11slu9nfn, `name` = XiaoYao, `phone` =
18660407361, `sex` = 2, `password` =
y$dWBZ/A/WGinWRlYvuFZfAeHYoq2sr46DzjDme83WETzAMR4wh9TrC, `description` =
测试内容</p>, `updated_at` = 2016-04-25
08:14:38 where `s_user_profile`.`user_id` = 1 and
`s_user_profile`.`user_id` is not null)
谢谢大神们。