【问题标题】:Laravel where and where not aren't working properlyLaravel 哪里和哪里不能正常工作
【发布时间】:2021-06-30 00:56:59
【问题描述】:

projectmember 表有一个列名状态。如果 $req 值没有打开,我想要将状态更新为 6 projectmember.member_id 归档

以下代码将所有状态更新为指定project_id的40

$req = [1,2,3];
    foreach ($req as $key => $item) {
        $updated = Projectmember::where('member_id','!=', $item )
                -> where('project_id','=', $id )
                ->update([
                    'status' => 40,
                ]);
    }

【问题讨论】:

    标签: laravel eloquent laravel-query-builder


    【解决方案1】:

    您可以使用WhereNotIn 来检查您在数组中的 id

    试试这个

    status 更新为6

    $req = [1, 2, 3, 4];
       
       $updated = Projectmember::whereNotIn('id', $req)->where('project_id', $id)->update([
            'status' => 6,
        ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-25
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      相关资源
      最近更新 更多