日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

laravel路由无法访问,报404,No query results for model [App\Models\...]

發(fā)布時間:2025/7/14 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 laravel路由无法访问,报404,No query results for model [App\Models\...] 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

今天遇到了一個問題,在routes/web.php中配置了路由,但始終無法訪問該路由,一直報404。

Route::resource('gift_packs', 'GiftPacksController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]); Route::get('gift_packs/test', 'GiftPacksController@test')->name('gift_packs.test');

然后我在app/Exceptions/Handler.php文件中,修改render()方法:

public function render($request, Exception $exception) {dd($exception);return parent::render($request, $exception); }

把異常打印出來:

No query results for model [App\Models\GiftPack].

先通過?php artisan route:list 查看路由列表

| Domain | Method | URI | Name | | | GET|HEAD | gift_packs/{gift_pack} | gift_packs.show | | | DELETE | gift_packs/{gift_pack} | gift_packs.destroy | | | PUT|PATCH | gift_packs/{gift_pack} | gift_packs.update | | | GET|HEAD | gift_packs/{gift_pack}/edit | gift_packs.edit | | | GET|HEAD | gift_packs/test | gift_packs.test |

原因是laravel路由訪問檢測是從上到下的。

針對同路徑,gift_packs/{gift_pack} 和 gift_packs/test,當我們訪問 /gift_packs/test時,路由 gift_packs/{gift_pack} 已經(jīng)解析了。

字符串 'test' 無法獲取GiftPack模型數(shù)據(jù),所以就報錯了。

解決方法是修改路由配置的上下位置:

Route::get('gift_packs/test', 'GiftPacksController@test')->name('gift_packs.test'); Route::resource('gift_packs', 'GiftPacksController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);

這樣就可以了。

?

  

轉(zhuǎn)載于:https://www.cnblogs.com/jkko123/p/10773000.html

總結(jié)

以上是生活随笔為你收集整理的laravel路由无法访问,报404,No query results for model [App\Models\...]的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。