I need to restrict access to some parts of the application depending on the user's login. I mean, for example, so that the user can only edit their own posts in the blogging application.
Is there a better approach than in every controller function, if the user does not own the required message, redirects to the error page?
For example, if my routes /post/{post_id}/edit, /post/{post_id}/preview, /post/{post_id}/deleteif I could somehow call for a general function of PostController, for example:
if(Post::find($post_id)->user_id != Auth::user()->id){
return View::make('access-error');
}
Thank!
source
share