title: Laravel 5 : multi-model middleware "Owner"
body: <p>I want to create a middleware to check if the authenticated user is the owner of the item. For a single model, the code is easy and would look something like : </p>
  
  <pre><code>    &lt;?php namespace App\Http\Middleware;
  
      use Closure;
  
      class Owner {
  
          public function handle($request, Closure $next)
          {
              $id = $request-&gt;segments()[1]; //get the id parameter
              $model = Model::find($id); // find the model from DB
  
              if(!$item)
                return 'not found'; //if item not found
  
              //check if authenticated user is owner
              if($item-&gt;user_id == \Auth::id()){ 
                return $next($request);
              }else{
                return 'not allowed';
              }
          }
      }
  </code></pre>
  
  <p>Now let's say I have multiple models (ModelX, ModelY, ModelZ) and I don't want to rewrite the middleware handle function several times. 
  How would one inject the referenced model in the middleware to make it accomodate multiple models from my app?</p>