Maximi
Maximi

Reputation: 569

Pass multiple parameters to controller from route in laravel 5

I have in

routes:

Route::get('feed/{type?}/{first?}/{second?}/{third?}', ['as' => 'feed', 'uses' => 'PostController@feed']);

controller:

public function feed(Request $request, $type, $first, $second, $third)
{
...

But this produce error:

ErrorException in PostController.php line 209:
Missing argument 3 for App\Http\Controllers\PostController::feed()

What I am doing bad? What I forgot? Thank you.

Upvotes: 0

Views: 2767

Answers (2)

Thamilhan
Thamilhan

Reputation: 13293

According to the Laravel Docs

Make sure to give the route's corresponding variable a default value

So it should be like this:

public function feed(Request $request = null, $type = null, $first = null, $second = null, $third = null)
{
...

You can replace null with default value of your choice.

Upvotes: 2

LC Yoong
LC Yoong

Reputation: 1842

You should declare the arguments as optional too like

public function feed(Request $request, $type = '', $first = '', $second = '', $third = '')
{

Upvotes: 1

Related Questions