如何处理未定义的路由异常?

时间:2016-04-23 06:56:31

标签: laravel exception-handling routes

我创建了动态侧边栏菜单,当我尝试插入新菜单时,收到错误消息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');

1 个答案:

答案 0 :(得分:0)

您应该使用Exception类来捕获任何类型的异常。

catch (\Exception $e)
{
        return Redirect::back()->with('infoMessage', "Route not defined.");
}