{"repo":"timacdonald/has-parameters","free":true,"listed":false,"github":"https://github.com/timacdonald/has-parameters","clone":"git clone https://github.com/timacdonald/has-parameters.git","description":"A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.","language":"PHP","stars":228,"topics":["laravel","middleware","helper","trait","php","hacktoberfest"],"license":"MIT","category":"dev-tools","readme_excerpt":"Has Parameters A trait for Laravel middleware that allows you to pass arguments in a more PHP'ish way, including as a key = value pair for named parameters, and as a list for variadic parameters. Improves static analysis / IDE support, allows you to specify arguments by referencing the parameter name, enables skipping optional parameters (which fallback to their default value), and adds some validation so you don't forget any required parameters by accident. Read more about the why in my blog post Rethinking Laravel's middleware argument API Installation You can install using composer: Basic usage To get started with an example, I'm going to use a stripped back version of Laravel's ThrottleRequests . First up, add the HasParameters trait to your middleware. You can now pass arguments to this middleware using the static with() method, using the parameter name as the key. You'll notice at first this is a little more verbose, but I think you'll enjoy the complete feature set after reading these docs and taking it for a spin. Middleware::with() The static with() method allows you to easily see which values represent what when declaring your middleware, instead of just declaring a comma seperate list of values. The order of the keys does not matter. The trait will pair up the keys to the parameter names in the handle() method. Skipping parameters If any parameters in the handle method have a default value, you do not need to pass them through - unless you are changing their value.","default_branch":null,"files":null,"tree":[],"storefront":"/r/timacdonald","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/timacdonald/has-parameters/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}