laravel路由无法访问,报404,No query results for model [App\Models\...]
今天遇到了一个问题,在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} 已经解析了。
字符串 'test' 无法获取GiftPack模型数据,所以就报错了。
解决方法是修改路由配置的上下位置:
Route::get('gift_packs/test', 'GiftPacksController@test')->name('gift_packs.test');
Route::resource('gift_packs', 'GiftPacksController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);
这样就可以了。
laravel路由无法访问,报404,No query results for model [App\Models\...]的更多相关文章
- laravel报错 No query results for model . 的解决方法
这个通常由路由绑定出的问题,注意有绑定模型的路由,同路径的路由需要放在没绑定路由的后面 例如:/product/comments和/product的是同路径,/product必须放在/product/ ...
- spring boot无法启动,或者正常启动之后无法访问报404的解决办法
以前用spring boot都是用idea的自动创建,或者是用的Jhipster创建的,就没有深究怎么去搭建.但是今天晚上心血来潮,想自己搭一个demo来整合一些技术,于是就花一点时间来手动搭.因为今 ...
- jfinal使用idea启动 访问报404 action not found
公司一个项目,在eclipse里面启动正常,换到idea里面启动后,启动没有报错,但是访问的时候会提示404 action not found. 百度了很多种解决方法 都没有解决. 今天脑子一转,想到 ...
- maven启动tomcat访问报404(url中没有项目名)
[INFO] Running war on http://localhost:8080/js_001(红色部分是项目名,要是没有的话是不能访问项目资源的) 但是我仍然不知道为什么有些maven项目却有 ...
- 解决springboot 新版本 2.1.6 spring-boot-starter-actuator 访问报404
pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...
- 项目发布到tomcat后,通过项目名称访问报404
查看tomcat发布地址发现和项目名称不一致 如果直接拷贝项目,可能也需要修改此选项 解决方案: 经过排查发现了原因: 首先说明一下项目 Maven+SSM 需要使用到 maven tomcat 7 ...
- springboot项目启动,但是访问报404错误
启动类Application上加了@ComponentScan(basePackages = {})这个注解导致controller扫描不到导致的,如果加了这个注解,springboot就不会扫描Ap ...
- jenkins部署报404错误
环境:tomcat 7+jdk1.7+win10 64 jenkins_1.5.23 部署完成后服务器启动输入网址:http://192.168.3.100:8080/jenkins打开无法访问报40 ...
- Laravel路由除了根目录全报404错误
Route::get('hello',function(){ return 'Hello World!'; }); 在laravel/app/Http/routes.php下添加上面的语句,然后再浏览 ...
随机推荐
- English 翻译到Vyeshal的软件
我或许可以做一个从英语到Vyeshal的翻译软件2333
- CSS——Flex
任何一个容器都可以指定为Flexbox布局 .flex-container { display: -webkit-flex; /* Safari */ display: flex; } 行内元素可以指 ...
- win 10 在vs2017下对mpi的安装以及认识
这里我先对MPI进行一下简单的介绍,MPI的全称是Message Passing Interface,即消息传递接口. 它并不是一门语言,而是一个库,我们可以用Fortran.C.C++结合MPI提供 ...
- Revit 命令添加下拉框
在学习revit制作下拉框时,需要分为三个步骤: 1.创建一个面板(panel). RibbonPanel panel10 = application.CreateRibbonPanel(Global ...
- 解决wxParse空格不解析的问题
遇到的问题: 相似问题:https://blog.csdn.net/qq_41619741/article/details/85774865 http://html51.com/info-41786- ...
- MySQL一千行笔记
/* 启动MySQL */ net start mysql /* 连接与断开服务器 */ mysql -h 地址 -P 端口 -u 用户名 -p 密码 /* 跳过权限验证登录MySQL */ mysq ...
- 学习使用github
自己尝试了一下用git bash完成了第一次下载与上传,感觉git desktop应该是讲bash某些需要输入代码的工作图形化了,但是因为感觉用起来有些不知所措,所以反倒是用代码的gitbash比较方 ...
- Crontab 执行时没有环境变量!
Crontab 执行时没有环境变量! Crontab 执行时没有环境变量! Crontab 执行时没有环境变量! 重要的事情说三遍,浪费我半天时间去找问题!! 非系统默认工具,执行时候需要加全路径!!
- docx httpheader头设置
设置contentType内容类型如下: Extension MIME Type .doc application/msword .dot application/msword .docx appli ...
- PSR-1 基本代码规范
基本代码规范 本篇规范制定了代码基本元素的相关标准, 以确保共享的PHP代码间具有较高程度的技术互通性. 关键词 “必须”("MUST").“一定不可/一定不能”("MU ...