ldc-mesbr-app/app/Models/Customers.php
2021-10-10 19:47:14 +02:00

46 lines
1 KiB
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
}
}
public function printedWalls()
{
return $this->hasMany(PrintedWalls::class, 'customer_id');
}
}