ldc-crm/app/Models/CustomerLogin.php
2021-10-26 12:01:40 +02:00

63 lines
1.4 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;
protected $attributes = [
'status' => false
];
protected $fillable = [
'password'
];
protected $casts = [
'status' => 'bool'
];
protected static function booted()
{
static::creating(function ($customerLogin) {
if (Hash::needsRehash($customerLogin->password)) {
$customerLogin->password = Hash::make(trim($customerLogin->password));
}
});
static::updating(function ($customerLogin) {
if (Hash::needsRehash($customerLogin->password)) {
$customerLogin->password = Hash::make(trim($customerLogin->password));
}
});
}
public function passwordMatch(string $password)
{
return Hash::check($password, $this->password);
}
/**
* 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);
}
}