如何在不需要auth的情况下设置主页(laravel)

发布于 2025-02-05 17:31:10 字数 420 浏览 1 评论 0原文

主页可以访问(并着陆)。

我正在尝试设置

use App\Http\Controllers\HomeController;    
Route::get('/', [HomeController::class, 'home']->withoutMiddleware(['auth']));

每个用户在登录后将其路由到其他页面之前的标准主页,该标准 是在尝试访问home.blade.php页面时尝试绕过Auth的要求,但是我会收到以下错误:

>因此,任何帮助将不胜感激。干杯!

I am trying to setup a standard homepage that every user has access to (and lands on), before they are routed to other pages after logging in.

Currently the web.php setup is

use App\Http\Controllers\HomeController;    
Route::get('/', [HomeController::class, 'home']->withoutMiddleware(['auth']));

The withoutMiddleware is to try and bypass the requirement of auth when trying to access the home.blade.php page, however I get the following error:

error message

Very new to Laravel, so any help would be greatly appreciated. Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹤舞 2025-02-12 17:31:10

路由不需要身份验证,除非它在路由Web.php文件或控制器中明确指定。

因此,它可以如下:

use App\Http\Controllers\HomeController;    
Route::get('/', [HomeController::class, 'home'];

Routes don't require authentication unless it's explicitly specified in the routes web.php file or the controller.

So it can be as following:

use App\Http\Controllers\HomeController;    
Route::get('/', [HomeController::class, 'home'];
绮烟 2025-02-12 17:31:10
Route::get('/', function () {
    if(Auth::guest()){
        return view('/home');
    }else{
        return redirect('/login');
    }
});
Route::get('/', function () {
    if(Auth::guest()){
        return view('/home');
    }else{
        return redirect('/login');
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文