0

I want to have second param as optional one.

Routes:

Route::get('/offers/preview/{id}/{string?}', 'OfferController@preview');

Controller:

public function preview($id, $string)
{
    // some code
}

Calling "offers/preview/101/test" looks ok.

Error by calling "offers/preview/101"

ErrorException in OfferController.php line 53:
Missing argument 2 for App\Http\Controllers\OfferController::preview()

Thank you in advance.

1
  • 1
    add default value for $string in your function. (eg. $string = '') Commented Jul 15, 2015 at 12:43

1 Answer 1

1

You need to add default value for the optional paramaters

public function preview($id, $string = '')
{
   // some code
}

see Laravel Routing

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.