//删除一条数据库记录的时候希望能自动删除这条记录关联的其它数据。 //可以用Eloquent的deleting事件来实现:class User extends Eloquent{
public function photos()
{
return $this->hasMany(‘Photo’);
}
public function posts()
{
return $this->hasMany(‘Post’);
}
protected static function boot()
{
parent::boot();
static::deleting(function($user) {
$user->photos()->delete();
$user->posts()->delete();
});
}}