Last active
August 29, 2015 14:03
-
-
Save amitittyerah/c39f6fe621993b715750 to your computer and use it in GitHub Desktop.
Custom token based filtering in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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