Pass two variable to method in Laravel

Hamad Essa :

i want to find post by slug also in url .. but the comments must be found by post_id

Controller

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

Route::get('post/{slug}', 'PagesController@post')->name('post.show');
Ryan Adhitama Putra :
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'));
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=8416&siteId=1