Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating Multiple Records using Eloquent (Laravel 5.4)

I have the following query that is working but I'm wondering what the Eloquent ORM equivalent would be?

       DB::table('exercises')->whereIn('id', $ids)->update($request->all());

Thanks

like image 735
Alex Avatar asked Mar 17 '17 16:03

Alex


People also ask

How do you update multiple rows from a single query using eloquent fluent?

$update = ItemTable::where('item_type_id', '=', 1); $update->colour = 'black'; $update->save();

How update multiple rows in SQL using single query in Laravel?

$where['page_id'] = [1,2,3]; $update = [['column' => 'value1'],['column' => 'value2']]; DB::table('my_table')->where($where)->update($update);

Which method is used to update data in Laravel?

We can update the records using the DB facade with update method. The syntax of update method is as shown in the following table. Run an update statement against the database.

What is advantage of eloquent in Laravel?

Eloquent is an ORM, which means can automatically handle the relationships of your models for you. You can retrieve related models without writing complex queries. You can even retrieve database information without any kind of database knowledge at all.


1 Answers

Eloquent equivalent is almost the same:

Exercise::whereIn('id', $ids)->update($request->all());
like image 66
Alexey Mezenin Avatar answered Nov 08 '22 15:11

Alexey Mezenin