Skip to content

Instantly share code, notes, and snippets.

@JeremiahTolbert
Created November 18, 2012 03:37
Show Gist options
  • Save JeremiahTolbert/4103342 to your computer and use it in GitHub Desktop.
Save JeremiahTolbert/4103342 to your computer and use it in GitHub Desktop.
Laravel Ajax Filter for Controllers
<?php
//This part would be included in the controller itself like so:
class Articles_Controller extends Controller {
public function __construct() {
parent::__construct();
$this->filter('before', 'csrf')->on('post');
$this->filter('before', 'ajax')->only(array('index', 'show', 'update'));
}
}
//This part would go in the route.php
Route::filter('ajax', function() {
if (Request::ajax() === false)
return Response::error('500');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment