118 lines
3.5 KiB
PHP
118 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
/**
|
|
* Customer.
|
|
*
|
|
* @property integer $crm_id CRM ID
|
|
* @property string $firstname Firstname
|
|
* @property string $lastname Lastname
|
|
* @property \Illuminate\Support\Carbon $birth_date Birth date.
|
|
* @property string $email Email
|
|
* @property string $password Password
|
|
* @property string $address Address
|
|
* @property string $address2 Second address
|
|
* @property string $town Town
|
|
* @property string $postal_code Postal code
|
|
* @property string $country Country
|
|
* @property string $phone Phone number
|
|
* @property-read string $email_verify_token Token for email verification
|
|
* @property-read boolean $email_verified Is the email verified ?
|
|
* @property-read string $password_token Password token
|
|
* @property-read \Illuminate\Support\Carbon $created_at Creation Date.
|
|
* @property-read \Illuminate\Support\Carbon $updated_at Last update Date.
|
|
*
|
|
* @method protected static function booted() The "booted" method of the model.
|
|
* @method private static function updatePassword($model) Update the password if needed.
|
|
*
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Participation[] $participations
|
|
* Associated participations.
|
|
*/
|
|
class Customer extends Authenticatable
|
|
{
|
|
use Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'crm_id',
|
|
'civility',
|
|
'firstname',
|
|
'lastname',
|
|
'birth_date',
|
|
'email',
|
|
'password',
|
|
'address',
|
|
'address2',
|
|
'town',
|
|
'postal_code',
|
|
'country',
|
|
'email_verify_token',
|
|
'email_verified'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
// * EVENT CLOSURES.
|
|
static::creating(function (self $model) {
|
|
static::updatePassword($model);
|
|
});
|
|
static::updating(function (self $model) {
|
|
static::updatePassword($model);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Update password.
|
|
*
|
|
* @param self $model
|
|
* @return void
|
|
*/
|
|
private static function updatePassword(self $model): void
|
|
{
|
|
if (Hash::needsRehash($model->password)) {
|
|
$model->password = Hash::make($model->password);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Has Many Participation relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function participations()
|
|
{
|
|
return $this->hasMany(Participation::class, 'user_id');
|
|
}
|
|
}
|