76 lines
2.4 KiB
PHP
76 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Traits\Models\ActivityLog;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property string $title_part1 Title part 1.
|
|
* @property string $title_part2 Title part 2.
|
|
* @property string $title_part3 Title part 3.
|
|
* @property string|null $picture Path of the picture (640px * 390px).
|
|
* @property string $picture_alt Picture alt attribute.
|
|
* @property string $picture_title Picture title attribute.
|
|
* @property string $video_id The youtube or vimeo video Id.
|
|
* @property boolean $display_video Wether to display video or picture.
|
|
* @property string $presentation_title Presentation title.
|
|
* @property string $presentation_content WYSIWYG - Presentation content.
|
|
* @property-read \Carbon\Carbon $created_at Created date.
|
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
|
*/
|
|
class Homepage extends Model
|
|
{
|
|
use ActivityLog;
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'title_part1',
|
|
'title_part2',
|
|
'title_part3',
|
|
'picture',
|
|
'picture_alt',
|
|
'picture_title',
|
|
'presentation_title',
|
|
'presentation_content',
|
|
'video_id',
|
|
'display_video',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'display_video' => 'bool'
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function () {
|
|
throw new \RuntimeException("Creating a new page is not authorized");
|
|
});
|
|
static::updating(function (self $model) {
|
|
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
|
|
});
|
|
static::updated(function (self $model) {
|
|
FileStorageHelper::removeOldFile($model, 'picture');
|
|
});
|
|
static::deleting(function () {
|
|
throw new \RuntimeException('Deleting a page is not authorized');
|
|
});
|
|
}
|
|
}
|