57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Lib\Helpers\ToolboxHelper;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Breeder extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'firstname',
|
|
'lastname',
|
|
'slug',
|
|
'biography',
|
|
'title',
|
|
'banner',
|
|
'banner_alt',
|
|
'banner_title',
|
|
'testimony',
|
|
'video',
|
|
'status'
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::creating(function (self $model) {
|
|
$model->slug = Str::slug($model->firstname . " " . $model->lastname);
|
|
ToolboxHelper::assertNoInternalBoUrls('testimony', $model->testimony);
|
|
$model->testimony = clean($model->testimony);
|
|
$model->banner = FileStorageHelper::storeFile($model, $model->banner);
|
|
});
|
|
static::updating(function (self $model) {
|
|
$model->slug = Str::slug($model->firstname . " " . $model->lastname);
|
|
ToolboxHelper::assertNoInternalBoUrls('testimony', $model->testimony);
|
|
$model->testimony = clean($model->testimony);
|
|
// * Store new banner if changed
|
|
if ($model->banner != $model->getOriginal('banner')) {
|
|
$model->banner = FileStorageHelper::storeFile($model, $model->banner);
|
|
}
|
|
});
|
|
}
|
|
}
|