I have this url: mywebsite.com/user/1/edit
I want my users to see this: mywebsite.com/edit-your-profile/
Is this possible when using Route::resource('user', 'UserController');? If yes, how do I do it :) ? I still want my app to be able to see user/1/edit as I use it in my middleware to prevent unauthorized access:
if ( \Auth::user()->id != $request->segment(2) ) {
return redirect()->back();
}
So, one pretty url for my user, a practical one for my app.
Based on your explanation, I take that a user can only edit their own profile. So
mywebsite.com/user/1/editshould NOT even be allowed. Instead, add this in your Route.php add:Route::get('/edit-your-profile','UserController@edit');and hardcode\Auth::user()->idinto youreditControllerand do not even allow the user to set the id. Why bother asking them for an ID if you already know what the id must be and ALL other ids will be rejected!PS. The html form for update should be at
@updateand the output that form should be sent to@edit. I just wanted to simplify the routing in the example.