Support the ongoing development of Laravel.io →
Requests Views
Last updated 2 years ago.
0
Solution

I would suggest you make a filter and apply it to your routes to keep your controllers clean

http://laravel.com/docs/routing#route-filters

Last updated 2 years ago.
0

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)

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0
function awesomeRedirect() {
    header("Location: " . app('url')->route('cms.login'));
}
Last updated 2 years ago.
0

Aah.. I see what you did there! :) Thanks!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ErikEklund erikeklund Joined 14 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.