153 lines
3.9 KiB
PHP
153 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Lib\Helpers\ToolboxHelper;
|
|
use App\Traits\Models\HasTranslations;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Uwil\Seo\Laravel\Interfaces\SeoInterface;
|
|
use Uwil\Seo\Laravel\Traits\SeoTrait;
|
|
|
|
/**
|
|
* @property integer $part2_product1_id
|
|
* @property integer $part2_product2_id
|
|
* @property string $seo_title
|
|
* @property string $seo_description
|
|
* @property string $part1_title
|
|
* @property string $part1_subtitle
|
|
* @property string $part1_text_1
|
|
* @property string $part1_text_2
|
|
* @property string $part1_text_3
|
|
* @property string $part2_title
|
|
* @property string $part2_subtitle
|
|
* @property string $part2_text
|
|
* @property array $part2_list
|
|
* @property string $part3_picture
|
|
* @property string $created_at
|
|
* @property string $updated_at
|
|
*/
|
|
class Home extends Model implements SeoInterface
|
|
{
|
|
use HasFactory;
|
|
use HasTranslations;
|
|
use SeoTrait;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'part2_product1_id',
|
|
'part2_product2_id',
|
|
'seo_title',
|
|
'seo_description',
|
|
'part1_title',
|
|
'part1_subtitle',
|
|
'part1_text_1',
|
|
'part1_text_2',
|
|
'part1_text_3',
|
|
'part2_title',
|
|
'part2_subtitle',
|
|
'part2_text',
|
|
'part2_list',
|
|
'part3_picture',
|
|
'part3_picture_alt',
|
|
'part3_picture_title',
|
|
'created_at',
|
|
'updated_at'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'part2_list' => 'array',
|
|
];
|
|
|
|
/**
|
|
* The translatable columns.
|
|
*
|
|
* @var array
|
|
*/
|
|
public $translatable = [
|
|
'seo_title',
|
|
'seo_description',
|
|
'part1_title',
|
|
'part1_subtitle',
|
|
'part1_text_1',
|
|
'part1_text_2',
|
|
'part1_text_3',
|
|
'part2_title',
|
|
'part2_subtitle',
|
|
'part2_text',
|
|
'part2_list',
|
|
'part3_picture',
|
|
'part3_picture_alt',
|
|
'part3_picture_title',
|
|
];
|
|
|
|
// * EVENTS
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::creating(function (self $model) {
|
|
self::manageFields($model);
|
|
});
|
|
static::updating(function (self $model) {
|
|
self::manageFields($model);
|
|
});
|
|
static::updated(function (self $model) {
|
|
FileStorageHelper::removeOldFile($model, 'part3_picture');
|
|
});
|
|
static::deleted(function (self $model) {
|
|
FileStorageHelper::removeFile($model, 'part3_picture');
|
|
});
|
|
}
|
|
|
|
// * METHODS
|
|
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @param Model $model
|
|
* @return void
|
|
*/
|
|
private static function manageFields(Model $model)
|
|
{
|
|
ToolboxHelper::assertNoInternalBoUrls('part1_text_1', $model->part1_text_1);
|
|
ToolboxHelper::assertNoInternalBoUrls('part1_text_2', $model->part1_text_2);
|
|
ToolboxHelper::assertNoInternalBoUrls('part1_text_3', $model->part1_text_3);
|
|
ToolboxHelper::assertNoInternalBoUrls('part2_text', $model->part2_text);
|
|
if (is_array($model->part2_list)) {
|
|
foreach ($model->part2_list as $item) {
|
|
ToolboxHelper::assertNoInternalBoUrls('part2_list', $item['value']);
|
|
}
|
|
}
|
|
$model->part3_picture = FileStorageHelper::storeFile($model, $model->part3_picture, true);
|
|
}
|
|
|
|
// * RELATIONSHIPS
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function product1()
|
|
{
|
|
return $this->belongsTo(Product::class, 'part2_product1_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function product2()
|
|
{
|
|
return $this->belongsTo(Product::class, 'part2_product2_id');
|
|
}
|
|
}
|