94 lines
2.4 KiB
PHP
94 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Strips\PictoEnum;
|
|
use App\Traits\Models\ActivityLog;
|
|
use App\Traits\Models\PlanificatedStatus;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property App\Enums\Strips\PictoEnum $picto Picto.
|
|
* @property string $text WYSIWYG restrained (blod and underline only). Text.
|
|
* @property boolean $published Publication status.
|
|
* @property \Carbon\Carbon|null $publish_at Publication date.
|
|
* @property \Carbon\Carbon|null $unpublish_at Unpublication status update date.
|
|
* @property-read \Carbon\Carbon $created_at Created date.
|
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
|
*
|
|
* @property-read \App\Models\News $news News Belongs to relationship.
|
|
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
|
|
*/
|
|
class Strip extends Model
|
|
{
|
|
use ActivityLog;
|
|
use HasFactory;
|
|
use PlanificatedStatus;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'picto',
|
|
'text',
|
|
'published',
|
|
'publish_at',
|
|
'unpublish_at',
|
|
'news_id',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'picto' => PictoEnum::class,
|
|
'published' => 'bool',
|
|
'publish_at' => 'datetime',
|
|
'unpublish_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $model) {
|
|
self::manageFields($model);
|
|
});
|
|
static::updating(function (self $model) {
|
|
self::manageFields($model);
|
|
});
|
|
}
|
|
|
|
// * METHODS
|
|
|
|
/**
|
|
* Manage model fields.
|
|
*
|
|
* @param self $model
|
|
* @return void
|
|
*/
|
|
private static function manageFields(self $model): void
|
|
{
|
|
self::makeStatusSense($model);
|
|
}
|
|
|
|
// * RELATIONS
|
|
|
|
/**
|
|
* Get the news that owns the strip.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function news(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
{
|
|
return $this->belongsTo(News::class);
|
|
}
|
|
}
|