それDB::raw()
が目的です:
$user = User::where_id($edit['id'])::update([
'name' => $edit['username'],
'email' => $edit['email'],
'password' => empty($edit['password']) ? DB::raw('`password`') : Hash::make($edit['password'])
]);
さらに良いのは、配列に設定しないことです。
$update_info = [
'name' => $edit['username'],
'email' => $edit['email']
];
if (! empty($edit['password'])) {
$update_info['password'] = Hash::make($edit['password']);
}
$user = User::where_id($edit['id'])::update($update_info);
User
がEloquent
モデルの場合、これを試してください:
$user = User::find($edit['id']);
$user->username = $edit['username'];
$user->email = $edit['email'];
if (! empty($edit['password'])) {
$user->password = Hash::make($edit['password']);
}
$user->save();