92 lines
2.0 KiB
PHP
92 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Tenant\Models;
|
|
|
|
use App\Domains\Attachable\Models\Attachment;
|
|
use App\Domains\Catalog\Models\Product;
|
|
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\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',
|
|
])]
|
|
class Tenant extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
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',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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');
|
|
}
|
|
|
|
public function productos(): HasMany
|
|
{
|
|
return $this->hasMany(Product::class, 'tenant_codigo', 'codigo');
|
|
}
|
|
|
|
public function menues(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
\App\Domains\Menu\Models\Menu::class,
|
|
'tenant_menues',
|
|
'tenant_codigo',
|
|
'menu_code',
|
|
'codigo',
|
|
'code'
|
|
)->withTimestamps();
|
|
}
|
|
}
|
|
|