File: D:/HostingSpaces/SBogers10/zelfverkopen.komma.pro/app/KommaApp/Customers/Models/Customer.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Customers\Models;
use App\KommaApp\Countries\Models\Country;
use App\KommaApp\CustomerProperties\Models\CustomerProperty;
use App\KommaApp\Orders\Models\Order;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Question
*
* @package App\KommaApp\Questions\Models
* @property int id
* @property int gender
* @property int site_id
* @property int active
* @property string code_name
* @property-read \App\KommaApp\Countries\Models\Country $country
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\CustomerProperties\Models\CustomerProperty[] $customerProperties
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Orders\Models\Order[] $orders
* @method static bool|null forceDelete()
* @method static \Illuminate\Database\Query\Builder|\App\KommaApp\Customers\Models\Customer onlyTrashed()
* @method static bool|null restore()
* @method static \Illuminate\Database\Query\Builder|\App\KommaApp\Customers\Models\Customer withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\KommaApp\Customers\Models\Customer withoutTrashed()
* @mixin \Eloquent
*/
class Customer extends Model
{
use SoftDeletes;
protected $table = 'customers';
protected $class = Customer::class;
const CUSTOMER_STATUS_ACTIVE = 1;
const CUSTOMER_STATUS_CLOSED = 0;
const CUSTOMER_GENDER_UNDEFINED = 0;
const CUSTOMER_GENDER_MALE = 1;
const CUSTOMER_GENDER_FEMALE = 2;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
// public $parent_id;
protected $fillable = [
'status',
'gender',
'last_name',
'email',
'phone',
'zip',
'house_number',
'house_number_addition',
'street',
'city',
'country_id',
];
/**
* A mutator that automatically formats the zip code.
*
* @param $zip
*/
public function setZipAttribute($zip)
{
$formatted = $zip;
$formatted = strtoupper($formatted);
$formatted = trim($formatted);
$formatted = str_replace(' ', '', $formatted);
$this->attributes['zip'] = $formatted;
}
/**
* A accessor that automatically formats the zip code.
*
* @param $zip
* @return mixed|string
*/
public function getZipAttribute($zip)
{
$formatted = $zip;
$formatted = strtoupper($formatted);
$formatted = trim($formatted);
$formatted = str_replace(' ', '', $formatted);
return $formatted;
}
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
/**
* Gets the country model for this model
*
* @return HasOne
*/
public function country(): HasOne
{
return $this->hasOne(Country::class);
}
public function customerProperties(): HasMany
{
return $this->hasMany(CustomerProperty::class);
}
/**
* Get the orders for this model
*
* @return HasMany
*/
public function orders(): HasMany
{
return $this->hasMany(Order::class);
}
public function __get($key)
{
if ($key == "title") {
return trans('orders.genderTitle.' . $this->gender) . ' ' . $this->last_name;
}
return parent::__get($key);
}
}