Update multiple rows of database in Laravel
Here is an easy way to do it.
$values = Value::where('project_id', $id)->update(['data'=>$data]);
I found it from this link
Hope it helps.
Update multiple rows at once Laravel Eloquent
Instead retrieving result, looping through, you can update directly,
$yes = Tour::whereIn('id', $request->promote)->update(['promote' => 1]);
$no = Tour::whereNotIn('id', $request->promote)->update(['promote' => 0]);
How to update multiple rows in existing table at once in laravel 8?
You are getting error because you are trying to update the collection of stdClass objects, which you got from the database.
Try like this:
DB::table('data')
->where('category_id', '=', 1)
->update([
'subject' => $request->get('subject') ?? null,
'grade' => $request->get('grade') ?? null
]);
Flash::success('updated successfully');
return redirect('marksheet');
This will update your records in the database. For the security of valid insert in the database, you can use database-transactions.
You should read about update()
in the docs.
Also, using models instead of Query builder is easier. You can read about that in the docs.
Updating Multiple Records using Eloquent (Laravel 5.4)
Eloquent equivalent is almost the same:
Exercise::whereIn('id', $ids)->update($request->all());
Update multiple values at once in Laravel using Eloquent
You can use eloquent to update multiple rows at once, either using a model or otherwise. For example:
Model::where($conditions)->update($newValues);
or
DB::table('users')->where($conditions)->update($newValues);
I would suggest taking a look at the Laravel documentation, https://laravel.com/docs/7.x/eloquent
Related Topics
Getting Student Name With Highest Total Mark in SQL
Select Rows Having 2 Columns Equal Value
Make SQL Select Same Row Multiple Times
Retrieve Varbinary Value as Base64 in Mssql
How to Find the Row Count for All Your Tables in Postgres
Oracle Pl/Sql String Compare Issue
Using SQL to Determine Word Count Stats of a Text Field
Sql Update Trigger Only When Column Is Modified
How to Specify a Password to 'Psql' Non-Interactively
Select First Row in Each GROUP BY Group
Remove Decimal Values Using SQL Query
Presto SQL - Converting a Date String to Date Format
How to Subtract One Month from a Date Column
How to Get Total Count Value Each Day Upto 5 Days
Get Last Record of a Table in Postgres
How to Get the Unmatched Records from Two Tables Using Joins