Home > Back-end >  How to update multiple user's Laravel
How to update multiple user's Laravel

Time:11-10

I'm creating a laravel project in which i have multiple users

what i want to achieve - I want to update stime of selected each user

My Code - which is not working

$user = User::where('admin_id','=', $ll);
$user->stime = $request->select;
$save = $user->save();

users table

CodePudding user response:

you can use Update method:

this method update existing records it accepts an array of column and value pairs indicating the columns to be updated. You may constrain the update query using where clauses:

User::where('admin_id','=', $ll)->update(['stime'=>$request->select]);

CodePudding user response:

If you want to update one or more users without fetching them first, use the update() method

User::where('admin_id', $ll)->update(['stime' => $request->select]);

If you want to update just one after fetching it.

$user = User::where('admin_id','=', $ll)->firstOrFail();
$user->stime = $request->select;
$save = $user->save();

CodePudding user response:

$user = User::where('admin_id','=', $ll)->get();
$user->stime = $request->select;
$save = $user->save();

I think you are missing ->get on your query.

  • Related