route model binding with query strings

Viewed 312

If I have a url like this:

localhost:8000?campaign=1

Is it possible to fetch the campaign from db like what we do in route model binding

1 Answers

Instead of localhost:8000?campaign=1 you should pass query string as: localhost:8000/campaign/1

and in Route:

Route::get('campaign/{id}', ['as' => 'campaigns.index', 'uses' => 'CampaignController@index']);

and in Controller:

public function index($id)
{
    //Your Code Goes Here
}

That's it! :)

Related