【发布时间】:2020-02-17 13:24:13
【问题描述】:
我也想在 url 中找到 slug 的帖子。 但是 cmets 必须通过 post_id 找到
控制器
public function post($slug,$id)
{
$post = Post::where('slug',$slug)->first();
$comments = Comment::where('post_id',$id)->get();
return view('content.post',compact('post','comments'));
}
路线
Route::get('post/{slug}', 'PagesController@post')->name('post.show');
【问题讨论】:
-
这是
$id不等于$postid 吗? -
这能回答你的问题吗? How to use variables in routes in laravel?
标签: mysql laravel laravel-5 laravel-6 laravel-6.2