Skip to content

Instantly share code, notes, and snippets.

@Glutnix
Created November 17, 2014 02:16
Show Gist options
  • Save Glutnix/76ce2c4e7cdd2eb17dd2 to your computer and use it in GitHub Desktop.
Save Glutnix/76ce2c4e7cdd2eb17dd2 to your computer and use it in GitHub Desktop.
Laravel 4.2 Route filters for checking ownership
Route::filter('admin', function()
{
if (Auth::user()->role !== 'admin') return Redirect::to('login');
});
Route::filter('albumOwner', function($route, $request)
{
$album = Album::findOrFail($route->getParameter('albums'));
if ( $album->user_id !== Auth::id() && Auth::user()->role !== "admin") {
return Redirect::to('login');
}
});
@Glutnix
Copy link
Author

Glutnix commented Nov 17, 2014

Thanks to @kategriffiths for letting me figure this out for her project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment