Laravel - Using (:any?) wildcard for ALL routes?

前端 未结 8 1210
时光取名叫无心
时光取名叫无心 2020-11-29 03:18

I am having a bit of trouble with the routing.

I\'m working on a CMS, and i need two primary routes. /admin and /(:any). The admin

8条回答
  •  难免孤独
    2020-11-29 03:58

    Thanks for the solution William. However methods 1 & 2 aren't working anymore Laravel 4, and in order to use solution #3 in Laravel 4 you will have to fire the 404 event in your start/global.php file.

    App::error(function(Exception $exception, $code)
    {
        // i.o. -> this is our catchall!
        // http://stackoverflow.com/questions/13297278/laravel-using-any-wildcard-for-all-routes
        Event::fire('404');
    
        return View::make('error')->with('exception', $exception)->with('code', $code);
    
        Log::error($exception);
    });
    

    Now we can handle this in our routes.php file:

    Event::listen('404', function() {
        // url?
        $url = Request::path();
    
        // LOGIC HERE
    
        // else
        return View::make('error');
    });
    

提交回复
热议问题