145 lines
3.6 KiB
PHP
145 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Tenant\Models;
|
|
|
|
use App\Domains\Attachable\Models\Attachment;
|
|
use App\Domains\Catalog\Enums\GroupLayout;
|
|
use App\Domains\Catalog\Enums\ProductLayout;
|
|
use App\Domains\Catalog\Models\CatalogItem;
|
|
use App\Domains\Menu\Models\Menu;
|
|
use App\Domains\Menu\Models\TenantMenu;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable([
|
|
'codigo',
|
|
'nombre',
|
|
'dominio',
|
|
'primary_color',
|
|
'secondary_color',
|
|
'danger_color',
|
|
'success_color',
|
|
'header_bg_color',
|
|
'footer_bg_color',
|
|
'header_logo_id',
|
|
'footer_logo_id',
|
|
'hero_config',
|
|
'event_config',
|
|
'search_product_layout',
|
|
'search_group_layout',
|
|
'search_items_per_page',
|
|
])]
|
|
class Tenant extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $attributes = [
|
|
'search_product_layout' => ProductLayout::ColumnWithImage->value,
|
|
'search_group_layout' => GroupLayout::Paginated->value,
|
|
'search_items_per_page' => 12,
|
|
];
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'codigo';
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'hero_config' => 'array',
|
|
'event_config' => 'array',
|
|
'search_product_layout' => ProductLayout::class,
|
|
'search_group_layout' => GroupLayout::class,
|
|
'search_items_per_page' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Attachment, $this>
|
|
*/
|
|
public function headerLogo(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Attachment::class, 'header_logo_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Attachment, $this>
|
|
*/
|
|
public function footerLogo(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Attachment::class, 'footer_logo_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Attachment, $this>
|
|
*/
|
|
public function heroBgImage(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Attachment::class, 'hero_bg_image_id');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsToMany<Attachment, $this>
|
|
*/
|
|
public function mainCarouselImages(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
Attachment::class,
|
|
'tenant_main_carousel_images',
|
|
'tenant_id',
|
|
'attachment_id'
|
|
)
|
|
->withPivot('orden')
|
|
->withTimestamps()
|
|
->orderByPivot('orden');
|
|
}
|
|
|
|
public function catalogItems(): HasMany
|
|
{
|
|
return $this->hasMany(CatalogItem::class, 'tenant_code', 'codigo');
|
|
}
|
|
|
|
/**
|
|
* @return BelongsToMany<SocialMedia, $this>
|
|
*/
|
|
public function socialMedia(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
SocialMedia::class,
|
|
'tenant_social_media',
|
|
'tenant_code',
|
|
'social_media_code',
|
|
'codigo',
|
|
'code'
|
|
)
|
|
->withPivot(['url', 'orden'])
|
|
->withTimestamps()
|
|
->orderByPivot('orden');
|
|
}
|
|
|
|
public function menues(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
Menu::class,
|
|
'tenants_menues',
|
|
'tenant_code',
|
|
'menu_code',
|
|
'codigo',
|
|
'code'
|
|
)
|
|
->using(TenantMenu::class)
|
|
->withPivot('static_content')
|
|
->withTimestamps();
|
|
}
|
|
}
|