112 lines
2.6 KiB
PHP
112 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
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',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'setup_completed' => 'boolean',
|
|
'setup_completed_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
// TODO: Später die Beziehung zu Products hinzufügen
|
|
// public function products(): HasMany
|
|
// {
|
|
// return $this->hasMany(Product::class);
|
|
// }
|
|
}
|