Mohamed Raza
Mohamed Raza

Reputation: 953

Laravel where and where not aren't working properly

projectmember table has a column name status. what i want is to update the status to 6 if $req value does'nt have on projectmember.member_id filed

following code update all the status to 40 of a specified project_id

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

Upvotes: 0

Views: 92

Answers (1)

Basharmal
Basharmal

Reputation: 1384

You can use the WhereNotIn to check your id in array

Try this

status is updated to 6

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

Upvotes: 1

Related Questions