Friday 15 March 2013

Laravel 5 Middleware -


Hi, I am using Laravel 5's Middleware and what I am doing, I have middleware which is being used in some controllers, and each of my controllers has their own configs, which I have to pass my middleware How do I do this?

"post-text" itemprop = "text">

If you have this middleware in "stack" ( App / Http / Kernel.php in $ Middleware in the array), you do not have a $ request -> route () available.

But, if you are using it on a routes.php file as the intermediate of a route or group of routes, then you can:

You want to create a config file, with the config item in the name of each root, then you get the root name in your middleware and the appropriate config loads.

Sorry if this is confusing, imagine this code:

Config / permissions.php

  Lt ;? Php returns [// root name here 'user.index' = & gt; // Your route option here ['option_a' = & gt; True, 'option_b' = & gt; Wrong,], 'user.edit' = & gt; ['Option_a' = & gt; True, 'option_b' = & gt; truth,     ],     /* ... */ ]; ? & Gt;  

Then you do something like handles in your middleware:

  public function handles ($ request, Closure $ next) {$ route = $ request-> Route () - & gt; GetName (); / * Check if this path is allowed in the config file / / (if "Permissions are received" ("Permissions. {$ Route}"), then {$ options = \ Config :: get ("Permissions {$ Route} "); / * Your options will be via route * / / * Now it is up to you what you want * /} and {/ * if not, then use the default option / $ / $$ ($ Request) return;}  

BTW, I recommend you use it for discussion:

www.laracast.com/discuss


No comments:

Post a Comment