What about using a route filter and checking for guest in the filter. That would keep the logic out of your controller. Just thinking out loud here...
Check em' out if you haven't already: (http://laravel.com/docs/4.2/routing#route-filters)
Hey all,
I want to add in a "preview" version of my site if you are visiting the site as a guest. However, I don't want to change my route names (if possible).
Short of putting conditional logic about what I should be showing in my controllers, is there anything that I can do to basically say (in the routes):
if guest
then point to the guest controller
else
point to the user's controller
I tried to override the routes but it did just that, overrode them, taking the latest one available in my routes.php file. I tried to add an if(Auth::check()) to my routes, but since routes are user-agnostic (and cached), it only takes the logged out version.
Do you guys have any suggestions on how I could do this nicely?
Thanks!
Right now, what I ended up doing (which I'm not a fan of) is in the 'before' filter for the user-specific, I have added in 'preview' filter which will basically redirect the user to the same route name but prefixed with 'preview'.
I wanted to avoid having that logic in my controller if possible - so that's why I'm avoiding that one @bestmomo.
Please or to participate in this conversation.