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)
{
});
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With