Laravel - how to update whole collection

后端 未结 1 1699
终归单人心
终归单人心 2021-01-25 00:46

I\'m trying to make a notification system with laravel. My idea was to get data and update instantly the \"is_delivered\" flag.

This is the code:

Model:          


        
相关标签:
1条回答
  • 2021-01-25 00:54

    You can run an update on the whole collection:

    DB::table('table_name')->whereIn('id', $collection->modelKeys())->update(['is_delivered' => 1]);
    
    0 讨论(0)
提交回复
热议问题