Laravel : 如何使用 table 中的外键更新布尔值

Laravel : How to update boolean value using foreign key in a table

这是我的数据库 table 我想使用 我想使用 user_id [=] 将 form_submissions table 的参与列更新为布尔值 1 14=]

这是我的控制器

 public function update($id)
    {
        $submission = Form_Submission::find($id);
        $submission->participation=1;
        $submission->save();
        return back();
    {

我使用按钮从 link 获取了 user_id 并将其传递给函数 有人可以告诉我如何使用 user_id 更新上述记录吗?

有了 user_id,您可以使用 where 检索特定的 Form_Submission,如下所示:

Form_Submission::where('user_id', $user_id)->get();

此资源:https://laravel.com/docs/7.x/queries#where-clauses

此外,要更新它,您可以使用 where - update,如下所示:

Form_Submission::where('user_id', $user_id)->update(['participation' => 1]);

此资源:https://laravel.com/docs/7.x/queries#updates

希望对您有所帮助!