ldc-crm/app/Models/CustomerLogin.php
2021-08-10 10:20:52 +02:00

55 lines
1.3 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 $fillable = [
'password'
];
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);
}
}