本文整理汇总了PHP中app\Menu::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Menu::firstOrNew方法的具体用法?PHP Menu::firstOrNew怎么用?PHP Menu::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Menu
的用法示例。
在下文中一共展示了Menu::firstOrNew方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translation
public function translation(Request $request)
{
$this->validate($request, ['title' => 'required', 'menu_id' => 'required|numeric', 'language_id' => 'required|max:2']);
//2. Find menu by id
$menu = Menu::firstOrNew(['id' => $request->input('menu_id')]);
try {
if ($menu->exists) {
$menuTranslation = MenuTranslation::firstOrNew($request->only('menu_id', 'language_id'));
if (!$menuTranslation->exists) {
$menuTranslation = new MenuTranslation($request->all());
$menuTranslation->save();
//5. FLASH MESSAGE BACK
Session::flash('flash_message', 'Menu successfully translated!');
} else {
$menuTranslation::where('menu_id', $request->input('menu_id'))->where('language_id', $request->input('language_id'))->update($request->only('content', 'title'));
//5. FLASH MESSAGE BACK
Session::flash('flash_message', 'Menu successfully translate updated!');
}
} else {
//5. FLASH MESSAGE BACK
Session::flash('flash_message', 'Menu not found!!!');
}
} catch (Exception $e) {
}
//6. REDIRECT BACK
return redirect()->back();
/*//1. Validation
$this->validate($request, [
'title' => 'required',
'menu_id' => 'required|numeric',
'language_id' => 'required|max:2',
]);
//2. Find menu by id
$menu = Menu::where([
'id'=> $request->input('menu_id'),
'status' => 1
]);
if($menu!=null){
$menuTranslations = MenuTranslation::where($request->only('menu_id','language_id'));
if($menuTranslations==null){
$menuTranslations = new MenuTranslation($request->all());
$menu->menuTranslation()->save($menuTranslations);
}else{
$menuTranslations->update($request->except('_token'));
}
//5. FLASH MESSAGE BACK
Session::flash('flash_message', 'Menu successfully translated!');
}else{
//5. FLASH MESSAGE BACK
Session::flash('flash_message', 'Menu not found!!!');
}
//6. REDIRECT BACK
return redirect()->back();*/
}