Reputation: 18318
I want to override model events and found this example code but am not sure I understand it completely.
SOURCE:
http://driesvints.com/blog/using-laravel-4-model-events/
There is a static method with another static method in it...How does that work? Or is it setting a static property in the boot method somehow?
<?php
class Menu extends Eloquent {
protected $fillable = array('name', 'time_active_start', 'time_active_end', 'active');
public $timestamps = false;
public static $rules = array(
'name' => 'required',
'time_active_start' => 'required',
'time_active_end' => 'required'
);
public static function boot()
{
parent::boot();
static::saving(function($post)
{
});
}
}
Upvotes: 3
Views: 26011
Reputation: 152890
static::saving()
just calls the static method saving
on itself (and parent classes if not existent in current class). So it is essentially doing the same as:
Menu::saving(function($post){
});
So it is registering a callback for the saving
event within the boot function.
Laravel documentation on model events
Upvotes: 8