Php Laravel更新数据库中的键和值
我在数据库中有键列和值列,如何从控制器更新它们 如何按键更新Php Laravel更新数据库中的键和值,php,laravel,eloquent,laravel-query-builder,Php,Laravel,Eloquent,Laravel Query Builder,我在数据库中有键列和值列,如何从控制器更新它们 如何按键更新 $settings = \App\Setting::where('type','synrisk')->get(); $settings->fill($request->all()); $settings->save(); Session::flash('message', 'تم التعديل بنجاح'); return redirect()->route('about_us_admin'); 我
$settings = \App\Setting::where('type','synrisk')->get();
$settings->fill($request->all());
$settings->save();
Session::flash('message', 'تم التعديل بنجاح');
return redirect()->route('about_us_admin');
我的表格回应
_token: "zLiFs10lNkuIZxu2DPyPwetsA3HCaNlgLb9L1w45",
full_name: "Mazen",
email: "mazen@aramex.com",
我的数据库
{
id: 4,
key: "phone_number_1",
value: "07777777",
type: "Aramex",
created_at: "2019-06-16 12:48:43",
updated_at: "2019-06-16 12:48:43"
},
{
id: 5,
key: "phone_number_2",
value: "07777777",
type: "Aramex",
created_at: "2019-06-16 12:48:43",
updated_at: "2019-06-16 12:48:43"
},
}
如果你做了这样的事情
$fullName = request()->only('full_name')
$fullNameKeyValue = [
'key' => array_key_first($fullName),
'value' => array_key_first(array_flip($fullName))
];
// You can extract this logic to a function and have checks in place as well
// like is_array() and array_key_exists() .
$settings->fill($fullNameKeyValue);
$settings->save();
你能再解释一下吗??您只能通过请求获得全名和电子邮件。。。你说的键和值是什么意思???@alithedeveloper我在键和电子邮件中保存值的类型(example@gmail.com)实际上,我不明白你的数据库结构。你能再举几个例子吗。电子邮件在哪里?全名在哪里?是否会为每个请求更新多行?