Reputation: 2139
I'm trying to add authentication into my Laravel app. Users can log in just fine, but I want to ensure that anyone who goes to a page is logged in - I don't want someone to bookmark a page within the application and go to it without ensuring they're logged in.
As such, I've been looking into Filters. I must not be implementing it right, because I get the following error call_user_func_array() expects parameter 1 to be a valid callback, no array or string given
when I go to one of the routes I've added the filter to, or any page that links to a filtered route.
Routes.php
Route::get( '/admin/login', 'UserController@getAdminLoginForm');
Route::get( '/admin/races', array('before' => 'auth', 'RaceController@getAllRacesView'));
Route::get( '/admin/geographies', array('before' => 'auth', 'GeographyController@getLocalGeographiesView'));
Route::get( '/admin/candidates', array('before' => 'auth', 'CandidateController@getAllCandidatesView'));
Filters.php
Route::filter('auth', function() {
if (Auth::guest()) return Redirect::guest('/admin/login');
});
I had the pages working prior messing around with filters, so what am I missing about implementing this?
Upvotes: 0
Views: 78
Reputation: 7578
Here's what the documentation says about adding a filter to controller actions:
Attaching A Filter To A Controller Action:
Route::get('user', array('before' => 'old', 'uses' => 'UserController@showProfile'));
So in short, you are missing the array key uses
. Try something like this:
Route::get('/admin/races', array('before' => 'auth', uses => 'RaceController@getAllRacesView'));
Upvotes: 1