'array', 'featured_photos' => 'array', ]; /* |-------------------------------------------------------------------------- | FUNCTIONS |-------------------------------------------------------------------------- */ public static function boot() { parent::boot(); static::creating(function ($model) { $limit = 6; $actualCount = HomeCarousel::query()->count(); if ($actualCount >= $limit) { return false; } }); static::deleting(function($obj) { if (count((array)$obj->photos)) { foreach ($obj->photos as $item) { \Storage::disk('public')->delete($item['file_path']); } } if (count((array)$obj->featured_photos)) { foreach ($obj->featured_photos as $item) { \Storage::disk('public')->delete($item['file_path']); } } }); } /* |-------------------------------------------------------------------------- | RELATIONS |-------------------------------------------------------------------------- */ public function parent() { return $this->belongsTo(HomeCarousel::class, 'parent_id'); } public function children() { return $this->hasMany(HomeCarousel::class, 'parent_id'); } /* |-------------------------------------------------------------------------- | SCOPES |-------------------------------------------------------------------------- */ /* |-------------------------------------------------------------------------- | ACCESSORS |-------------------------------------------------------------------------- */ /* |-------------------------------------------------------------------------- | MUTATORS |-------------------------------------------------------------------------- */ public function setPhotosAttribute($value) { $attribute_name = "photos"; $disk = "public"; $destination_path = "home_carousel"; $this->uploadImgMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path); } public function setFeaturedPhotosAttribute($value) { $attribute_name = "featured_photos"; $disk = "public"; $destination_path = "home_carousel"; $this->uploadImgMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path); } }