-1

我有这样的刀片文件:

 <div class="nav-item dropdown">
                @if (Auth::check())
                    <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">{{ Auth::user()->name }}</a>
                    <div class="dropdown-menu">
                        <a href="/profileDetail" class="dropdown-item">Profile</a>
                        <a href="order_history" class="dropdown-item">My Order</a> 
                            
                        <a href="#" class="dropdown-item" onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
                        Logout </a>

                        <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
                        @csrf
                        </form>
                    </div>
                
                @else
              

                <div class="nav-item dropdown">
                    <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Login</a>
                    <div class="dropdown-menu">
                        <a href="{{ route('user.login') }}" class="dropdown-item">Customer </a>
                        <a href="{{ route('user.register') }}r" class="dropdown-item">Register</a>
                            
                    </div>
                </div>
                
                @endif

                </div>

我的路由器是这样的:

/multi-auth router
Route::prefix('user') ->name ('user.') ->group (function(){

    Route::middleware (['guest']) ->group (function(){
        Route::view('/login', 'dashboard.user.login') ->name ('login');
        Route::view('/register', 'dashboard.user.register') ->name ('register');

    });

    Route::middleware(['auth']) ->group(function(){
        Route::view('/home', 'dashboard.user.home') ->name ('home');


    });
});

我已经添加use App\Http\Controllers\UserController;了 web.php,但我仍然发现找不到 UserController。我真的不知道我错在哪里。也许我不使用 Route::has (user.login)?

我正在使用 laravel/ui 但我已将刀片更改为我上面写的

4

1 回答 1

-1

但你没有在你的路线中提到 UserCotroller 吗?你希望 ot 怎么找到它?您正在通过您的路线返回视图,您没有将其重定向到您的控制器

这是你应该如何声明它:

 Route::get('/register', [UserController::class, 'create'])
            ->middleware('guest')
            ->name('register');

    Route::post('/register', [UserController::class, 'store'])
            ->middleware('guest');


    Route::get('/login', [UserController::class, 'create'])
            ->middleware('guest')
            ->name('login');

    Route::post('/login', [UserController::class, 'store'])
            ->middleware('guest');

在 create 方法中你可以写

return view(dashboard.user.login); 
于 2022-01-10T17:45:48.483 回答