Try changing
Route::any('/user/login', array('as' => 'login', 'uses' => 'UserController@login'));
to
Route::get('user/login', 'UserController@getLogin');
Route::post('user/login', 'UserController@postLogin');
Hey kreitje,
Even by changing it to:
Route::get('/user/login', array('as' => 'getlogin', 'uses' => 'UserController@login'));
Route::post('/user/login', array('as' => 'postlogin', 'uses' => 'UserController@login'));
it doesnt work. I still get a redirect loop.
Well, what your filter do is:
However, when you redirect, the second request is executed in a new instance of the framework, so the filter get re-executed. (you get where there is a loop in your logic?)
What you want to do is probably just block ajax request, but allow normal request to execute normaly. Your filter must be something like:
if (Auth::guest())
{
if (Request::ajax())
{
return Response::make('Unauthorized', 401);
}
}
Does it solve your problem?
Hey Atrakeur,
Why would there be a second re-execution if I set the redirect to a route that is ignored by the filter "assignment" ('except getLogin'):
$this->beforeFilter('auth', array('except' => array('getLogin', 'postLogin')));
Another thing I managed to find but seems quite illogical is that when I remove the filtering from my UserController it tells me that method [index] isn't found. I thought you didn't need to include the VERB (like get, post, delete, put, ...) in your controller routing.
Example: UserController@index instead of UserController@getIndex.
As it does seem to show me the dashboard afterwards when using the second example.
goowikns said:
Hey Atrakeur,
Why would there be a second re-execution if I set the redirect to a route that is ignored by the filter "assignment" ('except getLogin'):
So this isn't the problem. Maybe you can post a little more code to us so we can help better?
goowikns said:
Another thing I managed to find but seems quite illogical is that when I remove the filtering from my UserController it tells me that method [index] isn't found. I thought you didn't need to include the VERB (like get, post, delete, put, ...) in your controller routing.
Example: UserController@index instead of UserController@getIndex.
Well, you don't have to include the verb, But you have to set it to the exact name of the method. So if your method is getIndex, just write getIndex and not just index.
Where are you calling your $this->beforeFilter? What is $this in this context?
If you code is public, please post the github link so we can look at it?
Not sure what happened, works now, but it was partially due to the fact my routes weren't correctly written. I'm definetly going to start from scratch as I messed up so many things and generated way to many files at once without actually paying attention.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community