Skip to content

Instantly share code, notes, and snippets.

@dkesberg
Last active December 24, 2015 22:19
Show Gist options
  • Save dkesberg/6872094 to your computer and use it in GitHub Desktop.
Save dkesberg/6872094 to your computer and use it in GitHub Desktop.
Require auth basic on HTTP requests or functions
// router.php
Route::group(array('prefix' => 'api/v1'), function()
{
Route::resource('tweets', 'ApiController');
}
// RestController
class RestController extends BaseController {
public function __construct()
{
// auth on request type
$this->beforeFilter('auth.basic', array('on' => array('post','put','patch','delete')));
// auth on function
$this->beforeFilter('auth.basic', array('only' => array('create','store','edit', 'update', 'destroy')));
// auth except on function
$this->beforeFilter('auth.basic', array('except' => array('index','show')));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment