20-02-2026
This commit is contained in:
parent
854ce02bf6
commit
4d6b4930b2
128 changed files with 18247 additions and 2093 deletions
44
app/Casts/PartnerTypeCast.php
Normal file
44
app/Casts/PartnerTypeCast.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use App\Enums\PartnerType;
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PartnerTypeCast implements CastsAttributes
|
||||
{
|
||||
/**
|
||||
* Normalisiert DB-Werte (z.B. "retailer", "broker") zu gültigen Enum-Backing-Values.
|
||||
*
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
public function get(Model $model, string $key, mixed $value, array $attributes): ?PartnerType
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$normalized = match (strtolower((string) $value)) {
|
||||
'retailer' => PartnerType::Retailer->value,
|
||||
'manufacturer' => PartnerType::Manufacturer->value,
|
||||
'estate-agent', 'broker' => PartnerType::EstateAgent->value,
|
||||
'customer' => PartnerType::Customer->value,
|
||||
default => $value,
|
||||
};
|
||||
|
||||
return PartnerType::tryFrom($normalized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attributes
|
||||
*/
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes): ?string
|
||||
{
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $value instanceof PartnerType ? $value->value : (string) $value;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue