Skip to content

Instantly share code, notes, and snippets.

@Kindari
Created October 12, 2012 15:19
Show Gist options
  • Save Kindari/3879716 to your computer and use it in GitHub Desktop.
Save Kindari/3879716 to your computer and use it in GitHub Desktop.
Laravel Filter Route based on Role
<?php
Route::get('protected', array('before' => 'auth|role:admin', function() {
return "Only admins can see this";
}));
Route::filter('role', function ($role) {
if ( ! Auth::user()->has_role( $role ) )
{
return Response::error("401"); // not authorized
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment