Created
December 21, 2013 16:26
-
-
Save bwsewell/8071606 to your computer and use it in GitHub Desktop.
Event Listeners in Laravel
This file contains 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/global.php | |
require app_path().'/events.php'; | |
// app/events.php | |
Event::listen('student.change', function() { | |
Cache::forget('query.student.all'); | |
}) | |
// app/models/Student.php | |
class Student extends Eloquent { | |
protected $guarded = []; | |
public static function boot() | |
{ | |
static::saving(function() | |
{ | |
Event::fire('student.change'); | |
}); | |
} | |
} | |
// app/controllers/StudentController.php | |
class StudentsController extends BaseController { | |
public function index() | |
{ | |
return Student::remember(10, 'query.student.all')->get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment