Laravel guest middlewareLaravel 5 Protecting Routes with MiddlewareLaravel 5: Middleware don't work as expectedLaravel 5.2.14 with Duxet/RethinkDB Authentication Redirect User Seen as Guest in Home Routelaravel authentication always guestLaravel 5 restrict access to pages using middlewareLaravel middleware with multiple rolesLaravel - Confusion between routes and middleware and VueRouterCustom Middleware - 'Too Many Redirects' - LaravelCustom Middleware - Too Many Redirects - LaravelLaravel- 'auth' middleware not work

Java TreeMap.floorKey() equivalent for std::map

Methodology: Writing unit tests for another developer

Can someone suggest a path to study Mordell-Weil theorem for someone studying on their own?

Is a single radon-daughter atom in air a solid?

What is "industrial ethernet"?

Parameterize chained calls to a utility program in Bash

How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?

What size of powerbank will I need to power a phone and DSLR for 2 weeks?

Can humans ever directly see a few photons at a time? Can a human see a single photon?

What is the origin of Scooby-Doo's name?

Really Old Stock Valuation

Would it be a copyright violation if I made a character’s full name refer to a song?

What can I do with a research project that is my university’s intellectual property?

Do I have to explain the mechanical superiority of the player-character within the fiction of the game?

Can there be an UN resolution to remove a country from the UNSC?

How does a pilot select the correct ILS when the airport has parallel runways?

Has there been any indication at all that further negotiation between the UK and EU is possible?

Why does Linux list NVMe drives as /dev/nvme0 instead of /dev/sda?

Array initialization optimization

What does it mean to "control target player"?

Dates on degrees don’t make sense – will people care?

How to make clear to people I don't want to answer their "Where are you from?" question?

Greeting with "Ho"

Trainee keeps missing deadlines for independent learning



Laravel guest middleware


Laravel 5 Protecting Routes with MiddlewareLaravel 5: Middleware don't work as expectedLaravel 5.2.14 with Duxet/RethinkDB Authentication Redirect User Seen as Guest in Home Routelaravel authentication always guestLaravel 5 restrict access to pages using middlewareLaravel middleware with multiple rolesLaravel - Confusion between routes and middleware and VueRouterCustom Middleware - 'Too Many Redirects' - LaravelCustom Middleware - Too Many Redirects - LaravelLaravel- 'auth' middleware not work






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a page in my web app that should be blocked from logged in users. Similar to how a login or register page should not be accessible to already logged in users. I accomplished this by using guest middleware in controller constructor.



$this->middleware("guest")->only("page_action"); // like this


In this setup, if logged in user tries to visit that page they get redirected to home page. But I need to show a 404 not found page instead of redirecting. How can I do that?



In short, how can I make a page accessible to guest only and make it look like it does not exist to logged in users?










share|improve this question




























    0















    I have a page in my web app that should be blocked from logged in users. Similar to how a login or register page should not be accessible to already logged in users. I accomplished this by using guest middleware in controller constructor.



    $this->middleware("guest")->only("page_action"); // like this


    In this setup, if logged in user tries to visit that page they get redirected to home page. But I need to show a 404 not found page instead of redirecting. How can I do that?



    In short, how can I make a page accessible to guest only and make it look like it does not exist to logged in users?










    share|improve this question
























      0












      0








      0








      I have a page in my web app that should be blocked from logged in users. Similar to how a login or register page should not be accessible to already logged in users. I accomplished this by using guest middleware in controller constructor.



      $this->middleware("guest")->only("page_action"); // like this


      In this setup, if logged in user tries to visit that page they get redirected to home page. But I need to show a 404 not found page instead of redirecting. How can I do that?



      In short, how can I make a page accessible to guest only and make it look like it does not exist to logged in users?










      share|improve this question














      I have a page in my web app that should be blocked from logged in users. Similar to how a login or register page should not be accessible to already logged in users. I accomplished this by using guest middleware in controller constructor.



      $this->middleware("guest")->only("page_action"); // like this


      In this setup, if logged in user tries to visit that page they get redirected to home page. But I need to show a 404 not found page instead of redirecting. How can I do that?



      In short, how can I make a page accessible to guest only and make it look like it does not exist to logged in users?







      laravel-5 laravel-middleware laravel-5.8






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 8:46









      RagasRagas

      686721




      686721






















          2 Answers
          2






          active

          oldest

          votes


















          1














          In your method just check if the user is loggedIn, if then abort to 404 like below...



          if(IlluminateSupportFacadesAuth::check()) 
          return abort(404);


          #Rest of the code is for guest user.....
          #





          share|improve this answer






























            1














            The guest logic is inside inside AppHttpMiddlewareRedirectIfAuthenticated.



            if (Auth::guard($guard)->check()) 
            abort(404)


            return $next($request);


            Otherwise, you need to create a new middleware like @Atiqur suggested.






            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%2f55334032%2flaravel-guest-middleware%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              In your method just check if the user is loggedIn, if then abort to 404 like below...



              if(IlluminateSupportFacadesAuth::check()) 
              return abort(404);


              #Rest of the code is for guest user.....
              #





              share|improve this answer



























                1














                In your method just check if the user is loggedIn, if then abort to 404 like below...



                if(IlluminateSupportFacadesAuth::check()) 
                return abort(404);


                #Rest of the code is for guest user.....
                #





                share|improve this answer

























                  1












                  1








                  1







                  In your method just check if the user is loggedIn, if then abort to 404 like below...



                  if(IlluminateSupportFacadesAuth::check()) 
                  return abort(404);


                  #Rest of the code is for guest user.....
                  #





                  share|improve this answer













                  In your method just check if the user is loggedIn, if then abort to 404 like below...



                  if(IlluminateSupportFacadesAuth::check()) 
                  return abort(404);


                  #Rest of the code is for guest user.....
                  #






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 9:01









                  AtiqurAtiqur

                  1,4261621




                  1,4261621























                      1














                      The guest logic is inside inside AppHttpMiddlewareRedirectIfAuthenticated.



                      if (Auth::guard($guard)->check()) 
                      abort(404)


                      return $next($request);


                      Otherwise, you need to create a new middleware like @Atiqur suggested.






                      share|improve this answer



























                        1














                        The guest logic is inside inside AppHttpMiddlewareRedirectIfAuthenticated.



                        if (Auth::guard($guard)->check()) 
                        abort(404)


                        return $next($request);


                        Otherwise, you need to create a new middleware like @Atiqur suggested.






                        share|improve this answer

























                          1












                          1








                          1







                          The guest logic is inside inside AppHttpMiddlewareRedirectIfAuthenticated.



                          if (Auth::guard($guard)->check()) 
                          abort(404)


                          return $next($request);


                          Otherwise, you need to create a new middleware like @Atiqur suggested.






                          share|improve this answer













                          The guest logic is inside inside AppHttpMiddlewareRedirectIfAuthenticated.



                          if (Auth::guard($guard)->check()) 
                          abort(404)


                          return $next($request);


                          Otherwise, you need to create a new middleware like @Atiqur suggested.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 25 at 11:15









                          sentysenty

                          4,263859142




                          4,263859142



























                              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%2f55334032%2flaravel-guest-middleware%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