Laravel 5 - 在验证不工作之前

Laravel 5 - before auth not working

今天我尝试对我的应用程序进行一些更改。我试图首先通过身份验证传递所有页面。我尝试了这个网站上的答案之一。但这没有帮助。请帮忙。这是我在 routes.php

中的代码
<?php

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


Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]);
Route::group(['before' => 'auth'], function () {
    Route::get('home', function(){
        return \Redirect::to('twitter');
    });

   Route::get('twitter', 'HomeController@index');
   .
   .
   .
   .
});

我的文件中有几条路线。但只有 twitter 路线有效。

在laravel 5,

['before' => 'auth']

已弃用。但是,我应该使用

['middleware' => 'auth']

Laravel5 有中间件而不是过滤器。我假设您正在尝试仅向来宾显示某些页面,为此我们已经内置了一个来宾中间件。

Route::group(['middleware' => 'guest'], function () {
Route::get('home', function(){
    return \Redirect::to('twitter');
});

Route::get('twitter', 'HomeController@index');
});

如果需要,您也可以在控制器的特定功能上使用中间件,例如

class MyController extends Controller {

public function __construct()
{
    //to add auth middleware only on update method 
    $this->middleware('auth', ['only' => 'update'])
    //to add auth middleware on all fucntions expcept login
    $this->middleware('auth', ['except' => 'login'])
}

}