R
R
Ruslan Saifullin2018-09-19 10:04:31
Laravel
Ruslan Saifullin, 2018-09-19 10:04:31

How to pass get parameters to controller method?

Api method at:
site/api/registration
Takes 4 parameters in the get request:
site/api/registration?var1=1&var2=2&var3=3&var4=
4 their values ​​in the corresponding arguments:

public function registration( var1, var2, var3, var4)
{
    return 'registerUser';
}

The example from the documentation works if I change the url structure to site/api/registration/var1/1/var2/2
Route::get('api/registration/var1/{var1}/var2/{var2}', ['uses' =>'[email protected]', 'as'=>'registration']);

But unfortunately you need to save the structure site/api/registration?var1=1&var2=2&var3=3&var4=4
Tried
Route::get('api/registration?var1={var1}&var2={var2}', ['uses' =>'[email protected]', 'as'=>'registration']);

404 error didn't work.
What route should be written for this site/api/registration?var1=1&var2=2&var3=3&var4=4 request?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2018-09-19
@Sanasol

no route should be written for it.
api/registration and all
GET parameters are not part of the link.

D
Dmitry, 2018-09-19
@swede2k

public function registration(Request $request)
{
     $var1 = $request->var1; // $request->get('var1');
     $var2 = $request->var1; // $request->get('var2');
     etc...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question