ldc-mesbr-app/app/Models/Customers.php
Vincent BRIDIER f0c322c843 - Add API v1
- Add PHPCS
2021-04-27 17:29:47 +02:00

39 lines
913 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)
{
$country = trim(ucfirst(strtolower($country)));
switch ($country) {
case 'Belgique':
return 56;
break;
case 'Luxembourg':
return 442;
break;
default:
return 250; //France
}
}
}