User a {id} inside a route on Laravel User a {id} inside a route on Laravel laravel laravel

User a {id} inside a route on Laravel


You can use route() helper:

route('something.edit', ['id' => $event->data->id])


You shouldn't put an id in a route name. It's bad practice in my opinion. I would suggest that you use route resource.

php artisan make:resource MyController -m Something

This way, you can restful routes:

my/indexmy/createmy/storemy/{something}/editmy/{something}/updatemy/{something}/showmy/{something}/destroy

By the above pattern, your edit route will be /my/10/edit, and you data will be automatically fetched.

This way you can use policies to determine that item currently being updated belongs to the logged in user.