1

when I will click on a tag it go to specific url if no id found then go to reference My view

<a href="{{URL::to('user/')}}/?reference={{$user->username}}">
                    go there
                  </a>

my route

Route::get('/user/{id}/{reference?}', 'UserController@index')->name('/user');
2
  • Please clarify your question is there anything not working with the given code? Commented Jan 12, 2021 at 7:57
  • Your given route and href is different here. The href could be {{URL::to('user/'.$user->id.'/'.$user->username)}} Commented Jan 12, 2021 at 8:17

1 Answer 1

1

The query string is considered part of the inputs and not part of the URI for routing. If you want the 'id' part of the URI to be optional you would have to adjust your definition. Then in your controller you can access your reference query string parameter.

Route::get('user/{id?}', 'UserController@index')->name('user');

public function index(Request $request, $id = null)
{
    $reference = $request->input('reference');
    ...
}
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.