【问题标题】:Laravel 5 Polymorphic Relations Touch Parent TimestampLaravel 5 多态关系触摸父时间戳
【发布时间】:2017-06-28 11:46:29
【问题描述】:

我有以下具有多态关系的模型

class Sector extends Model {
      public function image() {
        return $this->morphOne('App\Models\Image', 'imageable');
      }
}

class Image extends Model {
    protected $touches = ['imageable'];

    public function imageable() {
        return $this->morphTo();
    }
}

我想在更新扇区图像时触摸父(扇区)模型的时间戳。我在 Image 模型上添加了 $touches 变量。

但这不起作用。

【问题讨论】:

    标签: laravel-5


    【解决方案1】:

    看看这是否有效。

    class Sector extends Model {
        public function image() {
          return $this->morphOne('App\Models\Image', 'imageable');
        }
    }
    
    class Image extends Model {
        protected $touches = ['sector'];
    
        public function imageable() {
            return $this->morphTo();
        }
    
        public function sector() {
            return $this->morphedByMany('App\Models\Sector', 'imageable');
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-05-26
      • 1970-01-01
      • 2015-04-25
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多