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;








0















I'm building a twitter-ish website and I'm having a problem with routing:



  1. 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');



  1. 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');



  1. 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');










share|improve this question






























    0















    I'm building a twitter-ish website and I'm having a problem with routing:



    1. 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');



    1. 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');



    1. 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');










    share|improve this question


























      0












      0








      0








      I'm building a twitter-ish website and I'm having a problem with routing:



      1. 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');



      1. 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');



      1. 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');










      share|improve this question














      I'm building a twitter-ish website and I'm having a problem with routing:



      1. 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');



      1. 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');



      1. 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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 14:52









      Rahimi0151Rahimi0151

      716 bronze badges




      716 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1














          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






          share|improve this answer


























            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
            );



            );













            draft saved

            draft discarded


















            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









            1














            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






            share|improve this answer































              1














              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






              share|improve this answer





























                1












                1








                1







                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






                share|improve this answer















                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







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 27 at 15:15

























                answered Mar 27 at 15:06









                kellymandemkellymandem

                8598 silver badges16 bronze badges




                8598 silver badges16 bronze badges





















                    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.



















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript