dongshi4078 2017-03-24 05:00
浏览 285

Laravel:如何在make:auth之后不要求登录

I just ran php artisan make:auth on my app which made it so that nothing can be accessed on the app without logging in.

I want some content to be visible to guest users, but don't know how. Let's say I just want them to be able to see the home page, the page they get directed to when they go to localhost:8000, instead of being instantly redirected to the localhost:8000/login page. How do I do this?

  • 写回答

1条回答

  • dongyi1524 2017-03-24 06:17
    关注

    You may add guest access within a specific controller, like so:

    public function __construct()
    {
        $this->middleware('guest', [ 'except' => 'logout' ]);
    }
    

    in the example above, all functions in the controller are accessible to guests except logout, for which you must be logged in.

    or within a router:

    Route::group(['middleware' => 'guest'], function(){
        Route::get(...
    });
    Route::get('/', 'HomeController@index')->name('home')->middleware('guest');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘