I would suggest you make a filter and apply it to your routes to keep your controllers clean
or write a plain old php function and put it in app/start/global.php
(better would be to create a helpers.php
and autoload it with composer/laravel)
Ah, the filter suggestion is probably best, that way I can avoid any extra code in the controller at all, and still keep the special checks in one place. I first opted out of this as I need a few different checks (like, allow access to the edit-user-page only if you are an admin OR if you are the user that is beeing edited), so I will probably need to create a couple of different filters, but it seems to be the best solution anyway.
Although I'm not sure how you mean the global function thing would work, as that would still have the same problem of not being able to redirect from within a function. You would still have to have something like this in the controller
if( $helper->isAdminOrUser( $user ) ) return Redirect::route('home');
Anyway, I think I'll go for a couple of different filters that can check each type of access, that seems the most convenient approach.
function awesomeRedirect() {
header("Location: " . app('url')->route('cms.login'));
}
Aah.. I see what you did there! :) Thanks!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community