【发布时间】:2018-08-22 08:43:03
【问题描述】:
课程如下:
class EventStepInstance extends Model
{
//..
public static function boot()
{
self::deleting(function($eventStepInstance) {
$classname = $eventStepInstance->step->handler;
if (!$classname || $classname == "default") {
$classname = 'Focus\Sped\Controller\DefaultFormHandler';
}
if (class_exists($classname)) {
$handler = App::make($classname);
$handler->deleteData($eventStepInstance->id);
}
return true;
});
return parent::boot();
}
public function step()
{
return $this->belongsTo('Focus\Sped\EventStep', 'event_step_id');
}
public function checkCompletion()
{
var_export(empty($this->step->classname)); // true
var_export($this->step->classname);
var_export(empty($this->step->classname)); // false
}
}
checkCompletion 中发生的位是预期行为吗?为什么会发生这种情况?我们唯一覆盖的 laravel 特定函数是两个类的 boot 函数,我们返回 parent::boot() 的结果。
【问题讨论】: