lundi 17 février 2020

Pass two variable to method in Laravel

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');


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire