ldc-mesbr-app/app/Models/Customers.php
2021-04-20 19:51:30 +02:00

38 lines
860 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Customers extends Model
{
protected $primaryKey = 'crm_id';
protected $fillable = ['crm_id', '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)
{
switch ($country)
{
case 'Belgique':
return 56;
break;
case 'Luxembourg':
return 442;
break;
default:
return 250; //France
}
}
}