Domanda

I want to make a pattern route, to redirect users to login page when they are not logged in. I searched but couldn't find a solution. as always Laravel's Documentation is useless!

I have this in my filter.php

Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::guest('login');
});

Route::filter('auth.basic', function()
{
return Auth::basic();
});

And this route in my routes.php

Route::when('/*', 'auth' );

but It's not working. How can I do that?

È stato utile?

Soluzione

Change the route declaration for login like this

Route::get( '/login', array('as' => 'login', 'uses' => 'UserController@getLogin') );

In your filters.php use

Route::filter('auth', function()
{
    if (Auth::guest()) return Redirect::route('login');
});

So, you can use

Route::when('*', 'auth' );

You can also use

Route::group(array('before' => 'auth'), function ()
{
    // Define all routes here with auth
    Route::get('my_first_route', function(){ /... });
    Route::post('my_second_route', 'MyController@myAction');
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top