gpt4 book ai didi

php - Laravel Route [dashboard] 未定义

转载 作者:行者123 更新时间:2023-12-04 13:46:04 24 4
gpt4 key购买 nike

今天第一次尝试使用 Laravel。当我尝试访问时出现以下错误:

InvalidArgumentException

Route [dashboard] not defined.


路线/web.php
Route::get('/', ['as' => '/', 'uses' => 'LoginController@getLogin']);
Route::post('/login', ['as' => 'login', 'uses' => 'LoginController@postLogin']);
Route::get('/logout', ['as' => 'logout', 'uses' => 'LoginController@getLogout']);

Route::group(['middleware' => ['authenticate', 'roles']], function (){
Route::get('/dashboard', ['as' => 'dashboard', 'uses' => 'DashboardController@dashboard']);
});
登录 Controller .php
class LoginController extends Controller
{
use AuthenticatesUsers;

protected $username = 'username';
protected $redirectTo = '/';
protected $guard = 'web';

public function getLogin()
{
if (Auth::guard('web'))
{
return redirect()->route('dashboard');
}
return view('login');
}

public function postLogin(Request $request)
{
$auth = Auth::guard('web')->attempt([
'username' => $request->username,
'password' => $request->password,
'active' => 1]);
if ($auth)
{
return redirect()->route('dashboard');
}
return redirect()->route('/');
}

public function getLogout()
{
Auth::guard('web')->logout();
return redirect()->route('/');
}
}
Error

最佳答案

as喜欢 name() .您应该使用以下两者之一:

Route::group(['middleware' => ['authenticate', 'roles']], function (){
Route::get('/dashboard', 'DashboardController@dashboard')->name('dashboard');
});

或者
Route::group(['middleware' => ['authenticate', 'roles']], function (){
Route::get('/dashboard', [
'as' => 'dashboard',
'uses' => 'DashboardController@dashboard']);
});

之后,您使用 php artisan route:clear 清除路由缓存

最后,您可以使用 php artisan route:list列出所有路由和操作绑定(bind)

关于php - Laravel Route [dashboard] 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48150789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com