Sunday, March 19, 2017

Passing parameters to middleware parameters

How do you pass additional parameters to middleware parameters?

I've read in the docs

Middleware parameters may be specified when defining the route by separating the middleware name and parameters with a :. Multiple parameters should be delimited by commas:

This can be implemented through

$this->middleware('example-middleware:param1');

or

$this->middleware('example-middleware:' . ExampleRepository::class);

So, my question lies on the second implementation, as you can see the parameter is a class path of an existing class. If my example class has parameters of it's own defined in its construct, how do you add these parameters in the middleware call ?

Here's the code for a ExampleRepository class

class ExampleRepository extends Repository implements BasicCrudInterface {

protected $example_param_repo;

public function __construct(ExampleParamRepository $example_param_repo)
{
    $this->example_param_repo= $example_param_repo;
}



via cjBucketHead

Advertisement