ldc-crm/app/Models/CustomerLogin.php

64 lines
1.4 KiB
PHP
Raw Normal View History

2020-12-01 17:02:10 +01:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2021-03-14 10:45:42 +01:00
use Illuminate\Support\Facades\Hash;
2020-12-01 17:02:10 +01:00
class CustomerLogin extends Model
{
use HasFactory;
2021-10-26 12:01:40 +02:00
protected $attributes = [
'status' => false
];
2021-03-14 10:45:42 +01:00
protected $fillable = [
'password'
];
2021-10-26 12:01:40 +02:00
protected $casts = [
'status' => 'bool'
];
2021-03-14 10:45:42 +01:00
protected static function booted()
{
static::creating(function ($customerLogin) {
2021-08-10 10:20:52 +02:00
if (Hash::needsRehash($customerLogin->password)) {
$customerLogin->password = Hash::make(trim($customerLogin->password));
}
2021-03-14 10:45:42 +01:00
});
static::updating(function ($customerLogin) {
2021-08-10 10:20:52 +02:00
if (Hash::needsRehash($customerLogin->password)) {
$customerLogin->password = Hash::make(trim($customerLogin->password));
}
2021-03-14 10:45:42 +01:00
});
}
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);
2020-12-01 17:02:10 +01:00
}
2021-03-14 10:45:42 +01:00
/**
* Brand BelongsTo relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function brand()
{
return $this->belongsTo(Brand::class);
}
2020-12-01 17:02:10 +01:00
}