Laravel 5.2 - Every route redirects to the homepag

2019-06-08 13:50发布

问题:

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!

回答1:

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'); }


回答2:

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
            ]
        );
}