I'm pretty fresh into laravel. I've used CakePHP a time or two, but not this.
Currently I'm trying to make a authentication system. The registration does work, so does logging in.
When I log in, my view gets displayed. But when I try to secure the controllers functions by using the auth
middleware:
public function __construct() {
$this->middleware("auth");
}
it keeps redirecting me to /
, but when it isn't there, it all works?
Also, when I try to do var_dump(Auth::check());
in the login function, it shows true
, but when I do it in my index (Where i keep getting wrongfully redirected to) it shows false
.
This is how I log in my users:
public function postLogin(LoginRequest $request) {
if ($this->auth->attempt($request->only("username", "password"))) {
return redirect("/me");
}
return redirect("/")->withInput()->withErrors([
"username" => "The credentials you entered did not match out system."
]);
}
Is it because of a bug in the code that causes this?
Thanks in advance.
Edit: I'm making use of Laravel 5.2. And also as requested: here are the routes.
Route::group(['middleware' => ['web']], function () {
Route::get('/', 'UnloggedController@index');
Route::get('/me', 'MeController@index');
});
Route::controller('/','Auth\AuthController');