title: Laravel 5 - Only Owner (creator) can edit/delete/view Entry
body: <p>I'm new to <code>Laravel</code> and have a little Question.</p>
  
  <p>I want to accomplish that just the Creator/Owner of a post can edit/view/delete it.</p>
  
  <p>Each Post belongs to a User and each User can have multiple Posts (1-to-Many relationship). That part works like a charm.</p>
  
  <p>To be more specific, if one of these routes is called:</p>
  
  <pre><code>GET mydomain.com/posts/{id} (show)
  
  GET mydomain.com/posts/{id}/edit (edit)
  
  PUT mydomain.com/posts/{id} (update)
  
  DELETE mydomain.com/posts/{id} (destroy)
  </code></pre>
  
  <p>the application should check if the currently authenticated user's id matches the posts user_id field.</p>
  
  <p>As far as I know this is not possible with a middleware because the middleware does not have access to the current Post-Object and I can't pass a paramenter to it.</p>
  
  <p>Currently I was able to accomplish my goal with a filter (I use Route-Model binding).</p>
  
  <pre><code>Route::filter('isOwnerOfPost', function() {
   if(Route::input('posts')-&gt;user_id !==  \Auth::id()) {
      abort(403);
   };
  });
  
  Route::get('posts', 'PostController@index');
  Route::group(['before' =&gt; 'isOwnerOfPost'], function(){
   Route::resource('posts', 'PostController', ['except' =&gt; ['index', 'create', 'store']]);
  });
  </code></pre>
  
  <p>But this solution seems a bit messy to me. I would have to create a new filter for every Model and I can't use resourceful routing (at least not completely).</p>
  
  <p>Is there a better way to accomplish such a behavior?</p>