I'm working with Laravel's default auth, the question I have is that to edit the profile, is it necessary to pass the user's $id in the edit form? this $id is captured by the EDIT method of the UserController controller and then by the UPDATE method, can we just use auth() from the form to the controller? Is there any way to make the urls cleaner?
I am new to laravel and I have to make a small application which will then have an api of
I attach a screenshot of the user profile, form and controller routes
Thanks for the help!
Is it necessary to pass the user's $id in the edit form?
I suppose you mean the form to update, in that case, yes, it is, otherwise you would not know which user you are going to update, oh unless you always call the logged in user by default
Auth
.Can only auth() be used from the form to the controller?
Yes, you can call the logged in user using
Auth::user()->id
.Is there any way to make the urls cleaner?
Laravel uses friendly routes, they are as clean as possible in my opinion, unless your conception of 'clean' is different.
Yes there is a way to make your urls cleaner .
For example:
With this single line if you go to the console and execute
php artisan route:list
, you will see the 4 basic urls such as Get, Post, Put and Delete.The urls are clean, what you want to do is not go
id
to edit or update and that makes sense since only the authenticated user could do that.What you have to do is:
// Route
// controller
I recommend you add the middleware
auth
to the constructor of your controller