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

Categories

HOME
google-chrome
libgdx
android-studio
ontouchlistener
clearcase
opencv-python
paypal-ipn
qc
softlayer
enums
stacktrace.js
websocket
malware
elisp
vue-resource
material-components
apache-kafka-connect
u-boot
graphql-js
kurento
mailing-list
port
yahoo
siesta
xades4j
vimeo
angular4
xbox360
temperature
phonegap-build
android-contacts
cocos2d-android
scheduled-tasks
node-webkit
hdl
maven-surefire-plugin
kaggle
rxjs5
candlestick-chart
perfino
mod-wsgi
morris.js
clipboard
npoi
django-import-export
spring-annotations
fatfs
region
monitor
steam-web-api
ms-media-foundation
winrm
apptentive
orchardcms-1.8
redgate
love2d
selenide
assemblies
python-sounddevice
grunt-contrib-watch
hdiv
hypothesis-test
amazon-elastic-beanstalk
node-apn
subforms
skip-lists
watir-webdriver
mongodb-aggregation
sesame
.when
ltrace
maatwebsite-excel
bpms
java-2d
wininet
bbc-micro
node-glob
facebook-ios-sdk
urbit
mnesia
teensy
ui4j
phpquery
textpattern
chicagoboss
astropy
apple
compositetype
sequence-sql
darwin
findersync
sunos
lifetime
comctl32
configurable-product
cout
dmake
.htpasswd
rails-api
strcmp
pbkdf2
sly-scroller
jquery-cycle
cgrectmake
idispatch
getopt-long
gwt-celltable
filelock
cewolf
simile
downgrade
active-record-query
chunking
facebook-fbml
dm
prism-2
objectinstantiation
downloadfile
account-management

Resources

Encrypt Message