Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
33.33% covered (danger)
33.33%
3 / 9
25.00% covered (danger)
25.00%
1 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CustomerLogin
33.33% covered (danger)
33.33%
3 / 9
25.00% covered (danger)
25.00%
1 / 4
16.67
0.00% covered (danger)
0.00%
0 / 1
 booted
33.33% covered (danger)
33.33%
2 / 6
0.00% covered (danger)
0.00%
0 / 1
5.67
 customer
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 brand
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 passwordMatch
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Factories\HasFactory;
6use Illuminate\Database\Eloquent\Model;
7use Illuminate\Support\Facades\Hash;
8
9class CustomerLogin extends Model
10{
11    use HasFactory;
12
13    /**
14     * The model's attributes.
15     *
16     * @var array
17     */
18    protected $attributes = [
19        'status' => false
20    ];
21
22    /**
23     * The attributes that are mass assignable.
24     *
25     * @var string[]
26     */
27    protected $fillable = [
28        'password'
29    ];
30
31    /**
32     * The attributes that should be cast to native types.
33     *
34     * @var array
35     */
36    protected $casts = [
37        'status' => 'bool'
38    ];
39
40    /**
41     * Perform any actions required after the model boots.
42     *
43     * @return void
44     */
45    protected static function booted()
46    {
47        static::creating(function ($customerLogin) {
48            if (Hash::needsRehash($customerLogin->password)) {
49                $customerLogin->password = Hash::make(trim($customerLogin->password));
50            }
51        });
52        static::updating(function ($customerLogin) {
53            if (Hash::needsRehash($customerLogin->password)) {
54                $customerLogin->password = Hash::make(trim($customerLogin->password));
55            }
56        });
57    }
58
59    // * RELATIONS
60
61    /**
62     * Customer BelongsTo relation
63     *
64     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
65     */
66    public function customer()
67    {
68        return $this->belongsTo(Customer::class);
69    }
70
71    /**
72     * Brand BelongsTo relation
73     *
74     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
75     */
76    public function brand()
77    {
78        return $this->belongsTo(Brand::class);
79    }
80
81    // * METHODS
82    /**
83     * Check if the user password is correct
84     *
85     * @param string $password
86     * @return boolean
87     */
88    public function passwordMatch(string $password): bool
89    {
90        return Hash::check($password, $this->password);
91    }
92}