2024-04-12 12:15:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2024-05-28 15:51:23 +02:00
|
|
|
use App\Enums\Approaches\ApproachTypeEnum;
|
2024-04-12 12:15:18 +02:00
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
|
|
|
use App\Traits\Models\ActivityLog;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2026-09-25 16:25:31 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2024-04-12 12:15:18 +02:00
|
|
|
|
|
|
|
|
/**
|
2026-09-25 16:25:31 +02:00
|
|
|
* @property \App\Enums\Approaches\ApproachTypeEnum $type Approach type (label or demarche).
|
|
|
|
|
* @property string $name Approach name.
|
|
|
|
|
* @property string $picture Approach picture.
|
|
|
|
|
* @property string $picture_alt Picture alt attribute.
|
|
|
|
|
* @property string $picture_title Picture title attribute.
|
|
|
|
|
* @property string $button_url Approach button url.
|
|
|
|
|
* @property bool $published Approach publication status.
|
2024-05-28 15:51:23 +02:00
|
|
|
* @property-read \Carbon\Carbon $created_at Created date.
|
|
|
|
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
2024-04-12 12:15:18 +02:00
|
|
|
*/
|
|
|
|
|
class Approach extends Model
|
|
|
|
|
{
|
|
|
|
|
use ActivityLog;
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var array<int, string>
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'type',
|
|
|
|
|
'name',
|
|
|
|
|
'picture',
|
|
|
|
|
'picture_alt',
|
|
|
|
|
'picture_title',
|
2024-06-27 12:10:22 +02:00
|
|
|
'button_url',
|
2024-04-12 12:15:18 +02:00
|
|
|
'published',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be cast.
|
|
|
|
|
*
|
|
|
|
|
* @var array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
2024-05-28 15:51:23 +02:00
|
|
|
'type' => ApproachTypeEnum::class,
|
2026-09-25 16:25:31 +02:00
|
|
|
'published' => 'boolean',
|
2024-04-12 12:15:18 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform any actions required after the model boots.
|
|
|
|
|
*/
|
|
|
|
|
protected static function booted(): void
|
|
|
|
|
{
|
|
|
|
|
static::creating(function (self $approach) {
|
|
|
|
|
$approach->picture = FileStorageHelper::storeFile($approach, $approach->picture, true);
|
|
|
|
|
});
|
2024-06-06 11:12:12 +02:00
|
|
|
static::updating(function (self $approach) {
|
2024-04-12 12:15:18 +02:00
|
|
|
$approach->picture = FileStorageHelper::storeFile($approach, $approach->picture, true);
|
|
|
|
|
});
|
|
|
|
|
static::updated(function (self $approach) {
|
|
|
|
|
FileStorageHelper::removeOldFile($approach, 'picture');
|
|
|
|
|
});
|
|
|
|
|
static::deleted(function (self $approach) {
|
|
|
|
|
FileStorageHelper::removeFile($approach, 'picture');
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-15 10:34:58 +02:00
|
|
|
|
|
|
|
|
// * RELATIONSHIPS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get MainSlides of the Approach (morph-to-many relationship).
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function mainSlides(): HasMany
|
2024-04-15 10:34:58 +02:00
|
|
|
{
|
|
|
|
|
return $this->hasMany(MainSlide::class);
|
|
|
|
|
}
|
2024-04-12 12:15:18 +02:00
|
|
|
}
|