41 lines
953 B
PHP
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
|
|
}
|
|
}
|
|
}
|