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

我刚刚在我的app上运行了 php artisan make:auth </ code>,这使得它什么都没有 可以在应用程序上访问而无需登录。</ p>

我希望访客用户可以看到一些内容,但不知道如何。 假设我只是希望他们能够看到主页,当他们转到 localhost:8000 </ code>时,他们被定向到的页面,而不是立即重定向到 localhost:8000 / 登录</ code>页面。 我该怎么做?</ p>
</ div>

展开原文

原文

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?

dongzhuang6417
dongzhuang6417 这是关于路由。本文档可能对您有所帮助。花点时间了解它,但绝对值得。
3 年多之前 回复

1个回答



您可以在特定控制器中添加访客访问权限,如下所示:</ p>

  public  function __construct()
{
$ this-&gt; middleware('guest',['except'=&gt;'logout']);
}
</ code> </ pre>

在上面的示例中,控制器中的所有功能都可供来宾</ em>访问,但 logout </ code>除外,您必须为其登录。</ p>

或在路由器中:</ p>

  Route :: group(['middleware'=&gt;'guest'],function(){
Route :: get( ...
});
Route :: get('/','HomeController @ index') - &gt; name('home') - &gt; middleware('guest');
</ code> < / pre>
</ div>

展开原文

原文

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐