Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sema314's avatar

Query string for a route

Hi all,

So the way that I currently have things, is that I'm calling it as /test/import

Route::get('test/import', [ 'as' => 'test.import', 'uses' => 'TestController@import' ]);

Which pulls in the correct import method inside TestController..

Here is what I'm trying to achieve:

How can I make it

test/import/?mode=test1 or test/import/?mode=test2 that calls on different methods depending on the mode query string

0 likes
10 replies
Sema314's avatar

So I want to be able to have

/test/import/?mode=update to always be the default, but I want to be able to pass in refresh and base it on another method.

So have /test/import/?mode=update be the default Route::get('test/import', [ 'as' => 'test.import', 'uses' => 'TestController@import' ]); like I have it now, but be able to change update to refresh and call another method.

MichalOravec's avatar
Level 75

@sema314 Like this?

public function import() {
    $mode = $request->query('mode', 'update');

    $this->update($mode);
}

public function update($mode) {
    // your code
}

Second parameter of ->query() is default.

1 like
Sema314's avatar

Ahh, thanks for explaining that! How can I make "mode=update" be the default in the class I provided above?

Sema314's avatar

Thanks so much! That explains a lot!

Sema314's avatar

Would the query string be as following? @michaloravec

Route::get('test/import/?mode={mode}', [ 'as' => 'test.import', 'uses' => 'TestController@import' ]);

test/import/?mode={mode}

MichalOravec's avatar

@sema314 No, let it like it you have it before so

Route::get('test/import', [ 'as' => 'test.import', 'uses' => 'TestController@import']);

If you use route helper you can do it like this

{{ route('test.import', ['mode' => 'update']) }}

Please or to participate in this conversation.