【问题标题】:Laravel 4.2 eloquent hasMany php empty results to true but false after read?Laravel 4.2 eloquent hasMany php empty 结果为真但读后为假?
【发布时间】: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() 的结果。

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    老实说,这看起来有点奇怪,我认为唯一的事情可能是该属性只能在阅读后才能访问,就像教义一样,他们这样做是为了提高性能,但据我所知,雄辩不应该这样做这个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多