2021-04-20 11:16:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class Customers extends Model
|
|
|
|
|
{
|
2021-04-27 17:29:47 +02:00
|
|
|
|
2021-08-13 11:48:06 +02:00
|
|
|
protected $primaryKey = 'hashcode';
|
2021-08-20 11:46:17 +02:00
|
|
|
protected $keyType = 'string';
|
2021-04-20 19:51:30 +02:00
|
|
|
|
2021-08-13 11:48:06 +02:00
|
|
|
protected $fillable = ['hashcode', 'email', 'country'];
|
2021-04-20 19:51:30 +02:00
|
|
|
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::creating(function ($customer) {
|
2021-04-27 17:29:47 +02:00
|
|
|
$customer->country = (new Customers())->getIsoCountry($customer->country);
|
2021-04-20 19:51:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
static::updating(function ($customer) {
|
2021-04-27 17:29:47 +02:00
|
|
|
$customer->country = (new Customers())->getIsoCountry($customer->country);
|
2021-04-20 19:51:30 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 17:29:47 +02:00
|
|
|
private function getIsoCountry($country)
|
2021-04-20 19:51:30 +02:00
|
|
|
{
|
2021-04-27 17:29:47 +02:00
|
|
|
$country = trim(ucfirst(strtolower($country)));
|
|
|
|
|
switch ($country) {
|
2021-04-20 19:51:30 +02:00
|
|
|
case 'Belgique':
|
|
|
|
|
return 56;
|
|
|
|
|
break;
|
|
|
|
|
case 'Luxembourg':
|
|
|
|
|
return 442;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return 250; //France
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-20 11:16:34 +02:00
|
|
|
}
|