drtoclr046994545
2015-05-16 11:25
浏览 29
已采纳

Laravel 5 - 在auth不工作之前

Today I tried to make some changes to my application. I tried to pass all pages through authentication first. I tried one of the answer on this site. But that didn't help. Please help. Here's my code in 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');
   .
   .
   .
   .
});

There are several routes in my file. But only twitter route works.

图片转代码服务由CSDN问答提供 功能建议

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

 &lt;?php 
 
Route :: get('/',function(){
return  view('homepage'); 
}); 
 
 
Route :: controllers([
'auth'=&gt;'Auth \ AuthController',
'密码'=&gt;'Auth \ PasswordController'  ,
]); 
Route :: group(['before'=&gt;'auth'],function(){
 Route :: get('home',function(){
 return \ Redirect ::  to('twitter'); 
}); 
 
 Route :: get('twitter','HomeController @ index'); 
。
。
。
。
}); \  n   
 
 

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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duangao7133 2015-05-16 11:34
    已采纳

    In laravel 5,

    ['before' => 'auth']

    is deprecated. But instead, I should use

    ['middleware' => 'auth']

    打赏 评论
  • douchun5969 2015-05-16 12:54

    Laravel5 has middlewares instead of filter. I assume you are trying to show certain page to only guests and for that we have a guest middleware already built in.

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

    you may also use middlewares on particular functions of your controller if you want, e.g

    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'])
    }
    
    }
    
    打赏 评论

相关推荐 更多相似问题