release
This commit is contained in:
@ -30,6 +30,7 @@ class HomeCarousel extends Model
|
||||
public $translatable = ['title','body'];
|
||||
protected $casts = [
|
||||
'photos' => 'array',
|
||||
'featured_photos' => 'array',
|
||||
];
|
||||
|
||||
/*
|
||||
@ -40,13 +41,28 @@ class HomeCarousel extends Model
|
||||
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']);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@ -85,6 +101,14 @@ class HomeCarousel extends Model
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user