Hello!
I would like to pass GET parameters from the URL to the Routes (web.php) and from the Routes to the Controller and from the Controller to the View.
So far, I have fully understood how to do it, when the URL looks like this:
https://******.com/foobar/111/222/333/
In this case, I would do it like this:
/routes/web.php
Route::get('/foobar/{aaa}/{bbb}/{ccc}', [FooController::class, 'foobar']);
app/Http/Controllers/FooContoller.php
public function foobar($aaa, $bbb, $ccc)
{
return view('foobar', compact('aaa', 'bbb', 'ccc'));
}
/resources/views/foobar.blade.php
aaa: {{ $aaa }}<br>
bbb: {{ $bbb }}<br>
ccc: {{ $ccc }}<br>
QUESTION 1
Just to be sure:
Is everything I wrote above correct and following best practice?
Question 2
HOW would I do it, when the GET parameters looked like this?
https://******.com/foobar/?a=111&b=222&c=333
Reminder:
In my example above, I used / / / to separate the values.
Now, I am using ? and &
I have only managed to figure out the ROUTES (web.php) so far in two different versions:
Option 1:
Route::get('/foobar', function(Request $request)
{
return $request->a." ".$request->b." ".$request->c;
});
Option 2:
Route::get('/blog', function()
{
return request('a')." ".request('b')." ".request('c');
});
However, I do NOT want to return the GET parameters in the ROUTE (web.php)
What I want is to pass the GET parameters from the URL to the Routes (web.php) and from the Routes to the Controller and from the Controller to the View (as I did above with the / / / version)
In my first example where I called the website like https://******.com/foobar/111/222/333/, I managed to pass the values all the way to the view.
But in the second attempt where I go with https://******.com/foobar/?a=111&b=222&c=333 I got stuck in the routes (web.php) and failed to pass it any further.
Please tell me, how I can pass the https://******.com/foobar/?a=111&b=222&c=333 parameters all the way to the view!
Thank you!
Yours
Ronaldo