How to use “OR” in route parameter?Check if a string is an email address in PHPLaravel 4 Route with username on first segmentLaravel 4 place username to URL using routesLaravel routes & usernames in routeslaravel advanced routing to multiple controllersMultiple forms in one view Laravel 5.1Laravel5: Conditional Routing (to make /usernickname pages)Why css and bootstrap is not loading in Laravel 5.3?Missing required parameters for route in LaravelLaravel 5.4 Mailables adding email addresses togetherLaravel: Wildcard Subdomain Routing not working
In xXx, is Xander Cage's 10th vehicle a specific reference to another franchise?
How many spells can a level 1 wizard learn?
Chord with lyrics - What does it mean if there is an empty space instead of a Chord?
How can I pack my food so it doesn't smell?
Can others monetize my project with GPLv3?
Moons that can't see each other
Is "stainless" a bulk or a surface property of stainless steel?
What animal has fat with the highest energy density?
Chess software to analyze games
How to decide whether an eshop is safe or compromised
Was Switzerland really impossible to invade during WW2?
Why do some academic journals requires a separate "summary" paragraph in addition to an abstract?
Sleeping solo in a double sleeping bag
How did Apollo 15's depressurization work?
Why would the President need briefings on UFOs?
Best Practice: dependency on data model names
Does Denmark lose almost $700 million a year "carrying" Greenland?
Are there any OR challenges that are similar to kaggle's competitions?
Why doesn't the Falcon-9 first stage use three legs to land?
How can I describe being temporarily stupid?
Convert HTML color to OLE
Starships without computers?
How to avoid using System.String with Rfc2898DeriveBytes in C#
Changing a TGV booking
How to use “OR” in route parameter?
Check if a string is an email address in PHPLaravel 4 Route with username on first segmentLaravel 4 place username to URL using routesLaravel routes & usernames in routeslaravel advanced routing to multiple controllersMultiple forms in one view Laravel 5.1Laravel5: Conditional Routing (to make /usernickname pages)Why css and bootstrap is not loading in Laravel 5.3?Missing required parameters for route in LaravelLaravel 5.4 Mailables adding email addresses togetherLaravel: Wildcard Subdomain Routing not working
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm building a twitter-ish website and I'm having a problem with routing:
- this code will bring the user to the profile page of the person with the given id.
Route::get('/profile/id', 'ProfileController@show')->name('profile.show');
- this code will bring the user to the profile page of the person with the given username.
Route::get('/profile/username', 'ProfileController@show')->name('profile.show');
- and finally, this code will bring the user to the profile page of the person with the given email.
Route::get('/profile/email', 'ProfileController@show')->name('profile.show');
I mean all these three URLs will show the user the same page:
example.com/profile/1
example.com/profile/rahimi0151
example.com/profile/rahimi0151@gmail.com
my question is:
is there a way to merge all these routes? like below:
Route::get('/profile/username', 'ProfileController@show')->name('profile.show');
laravel laravel-routing
add a comment |
I'm building a twitter-ish website and I'm having a problem with routing:
- this code will bring the user to the profile page of the person with the given id.
Route::get('/profile/id', 'ProfileController@show')->name('profile.show');
- this code will bring the user to the profile page of the person with the given username.
Route::get('/profile/username', 'ProfileController@show')->name('profile.show');
- and finally, this code will bring the user to the profile page of the person with the given email.
Route::get('/profile/email', 'ProfileController@show')->name('profile.show');
I mean all these three URLs will show the user the same page:
example.com/profile/1
example.com/profile/rahimi0151
example.com/profile/rahimi0151@gmail.com
my question is:
is there a way to merge all these routes? like below:
Route::get('/profile/username', 'ProfileController@show')->name('profile.show');
laravel laravel-routing
add a comment |
I'm building a twitter-ish website and I'm having a problem with routing:
- this code will bring the user to the profile page of the person with the given id.
Route::get('/profile/id', 'ProfileController@show')->name('profile.show');
- this code will bring the user to the profile page of the person with the given username.
Route::get('/profile/username', 'ProfileController@show')->name('profile.show');
- and finally, this code will bring the user to the profile page of the person with the given email.
Route::get('/profile/email', 'ProfileController@show')->name('profile.show');
I mean all these three URLs will show the user the same page:
example.com/profile/1
example.com/profile/rahimi0151
example.com/profile/rahimi0151@gmail.com
my question is:
is there a way to merge all these routes? like below:
Route::get('/profile/username', 'ProfileController@show')->name('profile.show');
laravel laravel-routing
I'm building a twitter-ish website and I'm having a problem with routing:
- this code will bring the user to the profile page of the person with the given id.
Route::get('/profile/id', 'ProfileController@show')->name('profile.show');
- this code will bring the user to the profile page of the person with the given username.
Route::get('/profile/username', 'ProfileController@show')->name('profile.show');
- and finally, this code will bring the user to the profile page of the person with the given email.
Route::get('/profile/email', 'ProfileController@show')->name('profile.show');
I mean all these three URLs will show the user the same page:
example.com/profile/1
example.com/profile/rahimi0151
example.com/profile/rahimi0151@gmail.com
my question is:
is there a way to merge all these routes? like below:
Route::get('/profile/username', 'ProfileController@show')->name('profile.show');
laravel laravel-routing
laravel laravel-routing
asked Mar 27 at 14:52
Rahimi0151Rahimi0151
716 bronze badges
716 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Am not sure about merging the routes but you could write your route like this
Route::get('/profile/identifier', 'ProfileController@show')->name('profile.show');
and then change the method signature for show
in ProfileController
to something like this
public function show($identifier)
if (is_numeric($identifier))
// do something
else if ($this->isEmail($identifier))
// do something
else
// assume it is a username, and do something with that
// method to check if value provided is an email
// preferably, move this to a file of your custom helper functions
private function isEmail($value)
// check if value is an email
// and return true/false indicating whether value is an email
And here is a link for a good way on how to check if a value is valid email address
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380206%2fhow-to-use-or-in-route-parameter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Am not sure about merging the routes but you could write your route like this
Route::get('/profile/identifier', 'ProfileController@show')->name('profile.show');
and then change the method signature for show
in ProfileController
to something like this
public function show($identifier)
if (is_numeric($identifier))
// do something
else if ($this->isEmail($identifier))
// do something
else
// assume it is a username, and do something with that
// method to check if value provided is an email
// preferably, move this to a file of your custom helper functions
private function isEmail($value)
// check if value is an email
// and return true/false indicating whether value is an email
And here is a link for a good way on how to check if a value is valid email address
add a comment |
Am not sure about merging the routes but you could write your route like this
Route::get('/profile/identifier', 'ProfileController@show')->name('profile.show');
and then change the method signature for show
in ProfileController
to something like this
public function show($identifier)
if (is_numeric($identifier))
// do something
else if ($this->isEmail($identifier))
// do something
else
// assume it is a username, and do something with that
// method to check if value provided is an email
// preferably, move this to a file of your custom helper functions
private function isEmail($value)
// check if value is an email
// and return true/false indicating whether value is an email
And here is a link for a good way on how to check if a value is valid email address
add a comment |
Am not sure about merging the routes but you could write your route like this
Route::get('/profile/identifier', 'ProfileController@show')->name('profile.show');
and then change the method signature for show
in ProfileController
to something like this
public function show($identifier)
if (is_numeric($identifier))
// do something
else if ($this->isEmail($identifier))
// do something
else
// assume it is a username, and do something with that
// method to check if value provided is an email
// preferably, move this to a file of your custom helper functions
private function isEmail($value)
// check if value is an email
// and return true/false indicating whether value is an email
And here is a link for a good way on how to check if a value is valid email address
Am not sure about merging the routes but you could write your route like this
Route::get('/profile/identifier', 'ProfileController@show')->name('profile.show');
and then change the method signature for show
in ProfileController
to something like this
public function show($identifier)
if (is_numeric($identifier))
// do something
else if ($this->isEmail($identifier))
// do something
else
// assume it is a username, and do something with that
// method to check if value provided is an email
// preferably, move this to a file of your custom helper functions
private function isEmail($value)
// check if value is an email
// and return true/false indicating whether value is an email
And here is a link for a good way on how to check if a value is valid email address
edited Mar 27 at 15:15
answered Mar 27 at 15:06
kellymandemkellymandem
8598 silver badges16 bronze badges
8598 silver badges16 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380206%2fhow-to-use-or-in-route-parameter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown