ldc-mesbr-app/app/Models/Customers.php
Vincent BRIDIER 203922849c
fix: PHPCBF
2025-04-03 09:30:16 +02:00

41 lines
953 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Customers extends Model
{
protected $primaryKey = 'hashcode';
protected $keyType = 'string';
protected $fillable = ['hashcode', 'email', 'country'];
protected static function booted()
{
static::creating(function ($customer) {
$customer->country = (new Customers())->getIsoCountry($customer->country);
});
static::updating(function ($customer) {
$customer->country = (new Customers())->getIsoCountry($customer->country);
});
}
private function getIsoCountry($country)
{
$country = trim(ucfirst(strtolower($country)));
switch ($country) {
case 'Belgique':
return 56;
break;
case 'Luxembourg':
return 442;
break;
default:
return 250;
// France
}
}
}