我创建了动态侧边栏菜单,当我尝试插入新菜单时,收到错误消息Route [nameroute] is not defined
。如何使用try catch处理此错误?
这是我的控制器文件。
DB::beginTransaction();
try
{
$insert = AppMenu::insertGetId([
'description' => $request->description,
'menu_url' => $request->menu_url ? $request->menu_url:null,
'menu_alias' => $request->menu_alias ? $request->menu_alias:null,
'ismenu' => $request->ismenu,
'parent' => $request->parent ? $request->parent:null,
'menu_icon' => $request->menu_icon,
'menu_order' => $request->menu_order
]);
DB::table('appmenu_role')->insert([
'appmenu_id' => $insert,
'role_id' => $role
]);
}
catch (\InvalidArgumentException $e)
{
return Redirect::back()->with('infoMessage', "Route not defined. ");
}
DB::commit();
Session::flash('successMessage', 'Menu Created');
return Redirect('menu');
答案 0 :(得分:0)
您应该使用Exception
类来捕获任何类型的异常。
catch (\Exception $e)
{
return Redirect::back()->with('infoMessage', "Route not defined.");
}