我很困惑,我得到一個錯誤,為什么我的路由過程不起作用,該錯誤給我 Route [index] 未定義,但另一方面我已經定義了 HomeController 的索引,看看我做的過程,注意:我使用 laravel 版本:5.8*我創建了一個 index.blade.php將路由添加到 web.php,我使用了這段代碼`Route::get('/index', 'HomeController@index');我將公共函數索引添加到 HomeController網頁.php Route::get('/index', 'HomeController@index');家庭控制器 public function index() {
return view('index');
}我的網址:錯誤:
4 回答

慕的地6264312
TA貢獻1817條經驗 獲得超6個贊
問題可能出在您的索引視圖中。
看起來您正在嘗試使用路由名稱訪問路由,并且您尚未定義索引路由的路由名稱。
所以在 web.php 中添加->name('index')
Route::get('/index', 'HomeController@index')->name('index');

蝴蝶不菲
TA貢獻1810條經驗 獲得超4個贊
您必須在路線中提供路線的名稱。
Route::get('/index', 'HomeController@index')->name('index');
您還可以使用以下語法
Route::get('/index', [
'as' => 'index',
'uses' => 'HomeController@index'
]);
有關更多信息,請查看文檔
https://laravel.com/docs/5.7/routing#named-routes

楊__羊羊
TA貢獻1943條經驗 獲得超7個贊
嘗試這個
如果您以這種方式使用路線
Route::get('/index', 'HomeController@index');
//then your url will be
URL/index
或使用這種方式
Route::get('/', 'HomeController@index');
//then your url will be
URL
- 4 回答
- 0 關注
- 130 瀏覽
添加回答
舉報
0/150
提交
取消