php

Laravel: How to redirect from controller to named route with params in URL

Problem

What would be the proper way to call a named route from my Laravel controller, but be able to include the parameters (such as the GET parameters, where I can pass an ID) ?

Solution

In Laravel, you can use the helper methods which is really super helpful and allows you to pass as many parameters as you defined in your route such as:

Route::get('/route/name/{id}/{name}', 'TestingController@fakeMethod')->name('route.name');
return redirect()->route('route.name', [
    'id' => 1,
    'name' => 'fake param'
]);

About the author

laravelrecipies