Skip to content

Instantly share code, notes, and snippets.

@amitittyerah
Last active August 29, 2015 14:03
Show Gist options
  • Save amitittyerah/c39f6fe621993b715750 to your computer and use it in GitHub Desktop.
Save amitittyerah/c39f6fe621993b715750 to your computer and use it in GitHub Desktop.
Custom token based filtering in Laravel
<?php
# app/models/TokenFilter.php
class TokenFilter {
public function filter()
{
if(!Token::valid(Input::get('token')))
{
return Response::json(array(
'error' => 'Your access token is not valid'
), 403);
}
}
}
# app/filter.php
Route::filter('auth.token', 'TokenFilter');
# app/routes.php
Route::get('/api/test', array('before' => 'auth.token', function()
{
return View::make('hello');
}));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment