Laravelのメソッドへの2つの変数を渡します

このハマド:

私は、URLにもスラグによってポストを見つけたい..しかし、コメントは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');
ライアンAdhitama息子:
Route::get('post/{slug}', 'PagesController@post')->name('post.show');
public function post($slug)
{
    $post = Post::where('slug',$slug)->first();
    $comments = Comment::where('post_id',$post->id)->get();
    return view('content.post',compact('post','comments'));
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=8718&siteId=1