122 lines
2.4 KiB
PHP
122 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\CCMS\Models;
|
|
|
|
use App\Traits\CreatedUpdatedBy;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Modules\CCMS\Traits\UpdateCustomFields;
|
|
|
|
// use Modules\CCMS\Database\Factories\PageFactory;
|
|
|
|
class Page extends Model
|
|
{
|
|
use HasFactory, UpdateCustomFields, CreatedUpdatedBy;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected $fillable = [
|
|
'title',
|
|
'slug',
|
|
'section',
|
|
'template',
|
|
'type',
|
|
'description',
|
|
'short_description',
|
|
'image',
|
|
'images',
|
|
'banner',
|
|
'custom',
|
|
|
|
'link',
|
|
|
|
'sidebar_title',
|
|
'sidebar_content',
|
|
'sidebar_image',
|
|
|
|
'button_text',
|
|
'button_url',
|
|
'button_target',
|
|
|
|
'meta_title',
|
|
'meta_keywords',
|
|
'meta_description',
|
|
|
|
'date',
|
|
'status',
|
|
'order',
|
|
|
|
'created_by',
|
|
'updated_by',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'section' => 'array',
|
|
'custom' => 'array',
|
|
];
|
|
}
|
|
|
|
protected function images(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: function ($value) {
|
|
if (empty($value)) {
|
|
return [];
|
|
}
|
|
|
|
$parts = explode(',', $value);
|
|
return array_map(fn($part) => asset(trim($part)), $parts);
|
|
}
|
|
);
|
|
}
|
|
|
|
protected function image(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => asset($value),
|
|
);
|
|
}
|
|
|
|
protected function banner(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => asset($value),
|
|
);
|
|
}
|
|
|
|
protected function sidebarImage(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => asset($value),
|
|
);
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->belongsToMany(
|
|
Page::class,
|
|
'page_relationship',
|
|
'parent_page_id',
|
|
'child_page_id',
|
|
'id',
|
|
'id'
|
|
);
|
|
}
|
|
|
|
public function parents()
|
|
{
|
|
return $this->belongsToMany(
|
|
Page::class,
|
|
'page_relationship',
|
|
'child_page_id',
|
|
'parent_page_id',
|
|
'id',
|
|
'id'
|
|
);
|
|
}
|
|
}
|