54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Lib\Utils;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Post extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'date_start' => 'datetime',
|
|
'date_end' => 'datetime',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'title',
|
|
'text',
|
|
'picture_home',
|
|
'picture_news',
|
|
'date_start',
|
|
'date_end',
|
|
'on_top'
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
static::creating(function (Post $post) {
|
|
if ($post->picture_home) {
|
|
$post->picture_home = Utils::storeImage($post->picture_home, $post->getTable());
|
|
}
|
|
if ($post->picture_news) {
|
|
$post->picture_news = Utils::storeImage($post->picture_news, $post->getTable());
|
|
}
|
|
});
|
|
|
|
static::updating(function (Post $post) {
|
|
if ($post->picture_home) {
|
|
$post->picture_home = Utils::storeImage($post->picture_home, $post->getTable());
|
|
}
|
|
if ($post->picture_news) {
|
|
$post->picture_news = Utils::storeImage($post->picture_news, $post->getTable());
|
|
}
|
|
});
|
|
parent::boot();
|
|
}
|
|
}
|