Laravel 5.2不正确的路由模型绑定不显示404 [英] Laravel 5.2 Incorrect Route Model Binding does not show 404
问题描述
在有关隐式路由模型绑定的Laravel 5.2文档中,写有:
In Laravel 5.2 docs about Implicit route model binding, there is written:
如果在数据库中找不到匹配的模型实例,则显示404 HTTP响应将自动生成.
If a matching model instance is not found in the database, a 404 HTTP response will be automatically generated.
路线:
Route::get('/product/{product}',function(Product $product){
dd($product);
});
当我输入URL参数的现有ID时,一切都会按预期进行.但是,当我输入URL不存在的产品ID时,得到的是模型[App \ Product]的无查询结果.
而不是响应404
.有什么想法吗?
When I enter into URL parameter existent ID, everything works as expected. But when I enter into URL nonexistent product ID, I got No query results for model [App\Product].
instead of response 404
. Any ideas why?
推荐答案
搜索后,我找到了解决方案.如果您在 resources/views/errors
中没有指定的错误模板文件,则将显示默认的Laravel消息.只需在 resources/views/errors
中创建404.blade.php文件.
After searching i found out solution. If you have no specified error template files in resources/views/errors
default Laravel message will be shown. Just create 404.blade.php file in resources/views/errors
.
这篇关于Laravel 5.2不正确的路由模型绑定不显示404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!