Get all routes, Laravel 4
Asked Answered
T

3

9

What I want is just to use one controller at the moment which should handle every request that comes to my laravel 4 application. The problem is that none of the solutions on stackoverflow or elsewhere are working for me.

That's what i currently have:

Route::any('(.*)', function(){
  return View::make('hello');
});

Now when browsing to the page I get an error everytime saying:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Hope somebody could help me out!

Teethe answered 23/4, 2013 at 20:18 Comment(0)
C
50

Regular expressions are set as requirements and not directly in the route.

Route::any('{all}', function($uri)
{
    return View::make('hello');
})->where('all', '.*');
Concerto answered 24/4, 2013 at 1:3 Comment(5)
Thx. How to use for example "TestController" here instead of directly returning a view?Rugging
Same deal, but instead of using a closure as the second parameter you'd do Route::any ('{all}', 'TestController@method');Concerto
It doesn't need to by any, it can be get, post or another HTTP verb too (etc: if you want to catch all get and not any other verb).Ehrman
This only works for a single segment it appears. If I go to site.com/asdadasd it's fine, but site.com/asdadasd/adadssa doesn't work. Any ideas?Bushido
This post can help understand this solution tooColorist
I
1
Route::group(array('prefix' => '/', 'before' => 'MAKEYOUROWNFILTER'), function()
{

    // your routers after the / ....
});

// and in filters.php

Route::filter('MAKEYOUROWNFILTER', function()
{

    // do stuff or just
    return View::make('hello');

});
Interweave answered 23/8, 2013 at 15:14 Comment(0)
B
0

Extending on #Jason Lewis's answer to redirect to the root page:

Route::any('{all}', function($uri)
{
    return Redirect::to('/');
})->where('all', '.*');
Bardwell answered 8/6, 2015 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.