Issue
How to get a part of the url?
query to be made:
$name = 'LeSant'; // (from url dinamic) //
$event = Dias::where('name', $name)->first();
How can I get name
from the url? /event/LeSant
Solution
It depends on how you are declared this route. You can specify model parameter and with laravel route binding you can inject model in your controller method https://laravel.com/docs/9.x/routing#customizing-the-key
In routes/web.php
:
Route::get('/events/{event:name}', [EventController::class, 'show']);
And in EventController
controller you can use something like that:
public function show(Event $event)
{
// do something with $event
}
Or if it not suits to you can get last element from request()->segments()
Answered By - Mykola Bokoch Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.