130 lines
3 KiB
PHP
130 lines
3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\PartnerTypeCast;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
|
|
class Partner extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'company_name',
|
|
'display_name',
|
|
'slug',
|
|
'type',
|
|
'brand',
|
|
'hub_id',
|
|
'parent_partner_id',
|
|
'salutation',
|
|
'first_name',
|
|
'last_name',
|
|
'street',
|
|
'house_number',
|
|
'zip',
|
|
'city',
|
|
'country',
|
|
'phone',
|
|
'website',
|
|
'description',
|
|
'logo_url',
|
|
'is_active',
|
|
'setup_completed',
|
|
'setup_completed_at',
|
|
'delivery_radius_km',
|
|
'assembly_radius_km',
|
|
'provision_fixed_amount',
|
|
'provision_rate_percentage',
|
|
'story_text',
|
|
'opening_hours',
|
|
'specialties',
|
|
'founded_year',
|
|
];
|
|
|
|
protected $casts = [
|
|
'type' => PartnerTypeCast::class,
|
|
'is_active' => 'boolean',
|
|
'setup_completed' => 'boolean',
|
|
'setup_completed_at' => 'datetime',
|
|
'opening_hours' => 'array',
|
|
'specialties' => 'array',
|
|
];
|
|
|
|
/**
|
|
* Ein Partner (Händler/Makler) kann einem Hub zugeordnet sein.
|
|
* Ein Hersteller ist evtl. "global" (hub_id = null).
|
|
*/
|
|
public function hub(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Hub::class);
|
|
}
|
|
|
|
/**
|
|
* Ein Partner (Firma) kann mehrere User-Logins haben.
|
|
*/
|
|
public function users(): HasMany
|
|
{
|
|
return $this->hasMany(User::class);
|
|
}
|
|
|
|
/**
|
|
* Für Kunden: Zugeordneter Makler/Händler (Parent-Partner)
|
|
*/
|
|
public function parentPartner(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Partner::class, 'parent_partner_id');
|
|
}
|
|
|
|
/**
|
|
* Für Makler/Händler: Zugeordnete Kunden (Child-Partners)
|
|
*/
|
|
public function childPartners(): HasMany
|
|
{
|
|
return $this->hasMany(Partner::class, 'parent_partner_id');
|
|
}
|
|
|
|
/**
|
|
* Alias für parentPartner (für bessere Lesbarkeit im Code)
|
|
*/
|
|
public function broker(): BelongsTo
|
|
{
|
|
return $this->parentPartner();
|
|
}
|
|
|
|
/**
|
|
* Alias für childPartners (für bessere Lesbarkeit im Code)
|
|
*/
|
|
public function customers(): HasMany
|
|
{
|
|
return $this->childPartners();
|
|
}
|
|
|
|
/**
|
|
* Ein Partner (Manufacturer) kann eine Marke haben
|
|
*/
|
|
public function brand(): HasOne
|
|
{
|
|
return $this->hasOne(Brand::class);
|
|
}
|
|
|
|
/**
|
|
* Ein Partner hat viele Produkte.
|
|
*/
|
|
public function products(): HasMany
|
|
{
|
|
return $this->hasMany(Product::class);
|
|
}
|
|
|
|
/**
|
|
* Polymorphe Beziehung zu Media (Team-Fotos, Showroom-Galerie, etc.).
|
|
*/
|
|
public function media(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
|
{
|
|
return $this->morphMany(Media::class, 'model');
|
|
}
|
|
}
|