Ad

How To Remove Filter From Some Of My Routes Laravel 4.2

I have routes for my project and I'm using Route::when('*', 'auth') to protect my routes by implement auth filter on every Route like given below:

// All the following routes must be filtered by the 'auth' filter.
Route::when('*', 'auth');

Route::resource('route_1', 'Controller_1);
Route::controller('route_2', 'Controller_2');
Route::get('route_3', '[email protected]_1');

It's clear that the user can not access the routes as a guest or in other words without log into.

Now I'v to use a couple of routes which could be accessed without login. I'm using the following code but it's not working and also implement auth filter on route_0:

// Following two routes must not be filtered by the 'auth' filter.
Route::get('route_0', '[email protected]');
Route::post('route_0', '[email protected]');

// All the following routes must be filtered by the 'auth' filter.
Route::when('*', 'auth');

Route::resource('route_1', 'Controller_1);
Route::controller('route_2', 'Controller_2');
Route::get('route_3', '[email protected]_1');

How can I remove auth filter from route_0? I also don't want to use auth filter separately on each route or controller. Any solution please?

Ad

Answer

You can use Route group like following

Route::get('/',  array('as' => 'home','uses' => '[email protected]'));

Route::group(array('before' =>'auth'), function()
{
 Route::get('about',  array('as' => 'about','uses' => '[email protected]'));
}
);

Put the routes those required to be filtered in the group and other outside. You can use multiple group too.

You can read about it here https://laravel.com/docs/4.2/routing#route-filters

Ad
source: stackoverflow.com
Ad