[英]404 not found Laravel with route argument
I come to you today because I don't really understand where my problem is coming from.我今天来找你是因为我真的不明白我的问题来自哪里。 When I try to pass a dynamic argument in my url, I systematically fall on a 404 page.当我尝试在我的 url 中传递动态参数时,我系统地陷入了 404 页面。 I looked in my db, there is the article, I looked in my model, it points well to this table of the db, I looked at my controller, I specify this article well... I do not understand too much.我看了我的数据库,有文章,我看了我的模型,它很好地指向了数据库的这张表,我看了我的控制器,我很好地指定了这篇文章......我不太明白。
My web.php:我的 web.php:
Route::get('/article/{article}', 'ArticleController@index');
My controller:我的控制器:
class ArticleController extends Controller
{
public function index($article)
{
$scopedArticle = Article::where('id', $article)->firstOrFail();
return view('article', compact('scopedArticle'));
}
}
My model:我的型号:
class Article extends Model
{
protected $table = 'articles';
protected $fillable = [
'titre', 'image', 'description',
];
}
My database:我的数据库:
So I don't really understand...所以我真的不明白...
With route model binding there is no need to add $scopedArticle = Article::where('id', $article)->firstOrFail();
使用路由模型绑定,无需添加$scopedArticle = Article::where('id', $article)->firstOrFail();
Example usage:用法示例:
goto http://yourstie.com/article/1转到http://yourstie.com/article/1
class ArticleController extends Controller
{
public function index(Article $article)
{
return view('article', compact('article'));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.