[英]how to update value in one column and automaticaly updated another column at different table laravel
i try to update value of name in table student and auto updated in column name at table users我尝试更新表学生中的名称值并自动更新表用户中的列名
my controller code is我的 controller 代码是
public function update(Request $request, $id)
{
$user = User::where('id', $id)->first();
$user->name = $request->name;
$user->save();
$student= Student::where('id', $id)->first();
$student->name = $request->name;
$student->save();
return redirect()->route('profilestudent.edit', Auth::user()->student->id);
}
no errors but it change another user's name at table users.没有错误,但它在表用户处更改了另一个用户的名称。
You should use the observers.你应该使用观察者。 When a User is updated, the Student will automatically also being updated.更新用户时,学生也将自动更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.