I want to save my array data but when I tried with foreach loop, it saves just last records.
Here is form blade (without unneccesary html code) ;
@foreach($categories as $key=>$category)
<input type="hidden" name="menusettings[][menu_name]" value="">
<input type="hidden" name="menusettings[][menu_slug]" value="category/" >
<input type="checkbox" checked name="menusettings[][menu_status]">
<input type="number" value="$i" name="menusettings[][menu_order]" >
@endforeach
And Controller; public function postUpdateMenu(Request $requests){
$menu = new Menu;
$request = $requests->get('menusettings');
foreach ($request as $reques) {
$menu_status = isset($reques['menu_status']) ? 1 : 0;
$menu->menu_name = $reques['menu_name'];
$menu->menu_slug = $reques['menu_slug'];
$menu->menu_status = $menu_status;
$menu->menu_order = $reques['menu_order'];
$menu->save();
}
return back();
}
Any advice ?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jWpHVT
via IFTTT
Aucun commentaire:
Enregistrer un commentaire