php
Laravel 5.0 masking routes
I'm new to Laravel world (using 5.0) and I'm learning how to route. I have this route Route::get('users/{id}', 'UserController#showProfile'); and the UserController public function showProfile($id) { return view('user.profile', ['user' => User::findOrFail($id)]); } everything works fine and the generated url is e.g. localhost:8000/users/1. It is possible to mask this route, having instead something like localhost:8000/users/profile, making the query under the hood? Thank you all
The simplest thing to do would be to simply pull in the authenticated user: Route::get('users/profile', 'UserController#showProfile'); public function showProfile() { return view('user.profile', ['user' => Auth::user()]); }
You can check the $id type. public function showProfile($id) { if(is_numeric($id)) { return view('user.profile', ['user' => User::findOrFail($id)]); } else { // Profile page. return view('user.profile_page'); } }
Related Links
Extract values from variables in PHP
Json_encode response to int array
PHP preg_match and sort by file CREATION date [duplicate]
Regular expressions replace
PHP Curl to echosign api outputting raw data
Cant split a string using php [closed]
how to identify a column in mysql when I have 2 with same name
Adding max_input_vars 3000 to my .htaccess file and php.ini not working
Missing HTTP Referrer info on IE/FF (works well on Chrome/Safari)
Is $query->get_result() the Correct Way to Get Results?
(PHP, MySQL) Where is this documented [duplicate]
Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: Cannot find encoding BUG
check if row exists else create one
How to make a button not to submit the form?
How to use include() properly?
Cant call multidimensional array