deyaamuhammad deyaamuhammad - 2 years ago 170
SQL Question

Laravel 5 how to find and update multiple records?

Now i have this table called


i use it to save my project configurations

mysql config table

Now i use this Eloquent method to fetch table?

$config = Config::pluck('value','name')->all();

The question is How to update the whole table from an array?

[_method] => PUT
[_token] => FvpYFD6GeVaNIHTOwquycLlarhLuNoL6MiLwSqkJ
[site_title] => title
[site_description] => description
[site_keywords] => keyword1,keyword2
[taxonomy_paginate] => 20
[comment_disqusEnable] => on
[comment_disqusUsername] => username

Thanks in Advance.

Answer Source

You can update multiple records using a loop. For example:

$configs = Config::all();

foreach ($configs as $config) {
  $config->name = 'new name';
  $config->value = 'new value';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download