1

I just started an laravel 5.2 application. Every route I take (/register, /logout, login,...) redirects me to the homepage.

Here are my routes

<?php
Route::group(['middleware' => ['web']], function () {
//Register
    Route::get('/register', 'Auth\AuthController@getRegister');
    Route::get('/register/success', 'Auth\AuthController@getRegisterSuccess');

    Route::post('/register', 'Auth\AuthController@PostRegister');

//Login
    Route::get('/login', 'Auth\AuthController@getLogin');

    Route::post('/login', 'Auth\AuthController@PostLogin');

//Password Reset
    Route::get('/password/reset/email', 'Auth\PasswordController@getEmail');
    Route::get('/password/reset/{token}', 'Auth\PasswordController@getToken');
    Route::get('/password/reset/sent', 'Auth\PasswordController@getSent');

    Route::post('/password/reset/email', 'Auth\PasswordController@postEmail');
    Route::post('/password/reset', 'Auth\PasswordController@postReset');
});


Route::group(['middleware' => ['web', 'auth']], function () {
    Route::get('/logout', 'Auth\AuthController@getLogout');
});

Route::get('/', function () {
    return view('welcome');
});

when I remove the Route::group(['middleware' => ['web']], function () { line I can access the page but it gives me the error of

Undefined variable: errors

That's why the web middelware is required, So I'm kinda stuck.

The controller and views work. It's just this redirect that I can't figure out.

Thanks for your help!

Nicolas
  • 4,526
  • 17
  • 50
  • 87

2 Answers2

2

You need to make changes in your AuthController and put where do you want to be redirected.

Then you need to add this in every controller you have:

public function __construct() { $this->middleware('auth'); }
  • Tried that, but without any result. – Nicolas Mar 24 '16 at 15:25
  • this worked! Can briefly explain what it exactly it does? Thanks! – Nicolas Mar 24 '16 at 15:52
  • Like every construct function, whenever you use controller, this function will be automatically called. It means that you are logged in and that you can use that method from that route. Im sry for my bad eng, i hope that you understand – Sladjan Marjanovic Mar 24 '16 at 16:08
  • At first the answer wasn't clear enough, but in the comment you really clearly solved the issue. +1 – Peter Apr 20 '16 at 06:43
0

You have to make a blade template like auth.blade.php in resources/views. Then you need to make the view from your controller with a return like:

   public function getLogin(){
        return view(
            "auth",
            [
                'username' => username,
                'password' => password
            ]
        );
}
Nabsta
  • 101
  • 3
  • 12