Sunday, 15 September 2013

php - Laravel custom filter -



php - Laravel custom filter -

i need able access number of routes if status met. else should not have access routes.

i thought should done filter think i'm missing how work.

so filter:

route::filter('my.filter', function() { //some code regarding said status if($mycondition==true){ //what set here? }else{ //error message } }

and in routes have:

route::group(array('before' => 'my.filter'), function() { route::resource('cities', 'citiescontroller'); //... many more controllers here });

but examples have seen have redirect within filter in if part. don't want that, want, if status in filter true, see url.

if wanna have filter stop farther execution of routes (and controllers , on) have to:

return (e.g. redirect) or throw exception

in laravel can pretty easily:

route::filter('my.filter', function() { //some code regarding said status if($mycondition==true){ // here have nil flip if... }else{ app::abort(403); } }

official docs

little sidenote: mentioned above in comment flip if. that:

route::filter('my.filter', function() { //some code regarding said status if($mycondition==false){ app::abort(403); } }

php laravel laravel-4 routes

No comments:

Post a Comment