92 lines
1.9 KiB
PHP
92 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class CustomerLogin extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The model's attributes.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $attributes = [
|
|
'status' => false
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var string[]
|
|
*/
|
|
protected $fillable = [
|
|
'password'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $casts = [
|
|
'status' => 'bool'
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::creating(function (self $model) {
|
|
if (Hash::needsRehash($model->password)) {
|
|
$model->password = Hash::make(trim($model->password));
|
|
}
|
|
});
|
|
static::updating(function (self $model) {
|
|
if (Hash::needsRehash($model->password)) {
|
|
$model->password = Hash::make(trim($model->password));
|
|
}
|
|
});
|
|
}
|
|
|
|
// * RELATIONS
|
|
|
|
/**
|
|
* Customer BelongsTo relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
/**
|
|
* Brand BelongsTo relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function brand()
|
|
{
|
|
return $this->belongsTo(Brand::class);
|
|
}
|
|
|
|
// * METHODS
|
|
/**
|
|
* Check if the user password is correct
|
|
*
|
|
* @param string $password
|
|
* @return boolean
|
|
*/
|
|
public function passwordMatch(string $password): bool
|
|
{
|
|
return Hash::check($password, $this->password);
|
|
}
|
|
}
|