Completed
Push — development ( e80362...5ad269 )
by Claudio
02:41
created

ChocolateyId::getRelatedAzureIdAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Collection;
6
use Illuminate\Support\Facades\Config;
7
8
/**
9
 * Class ChocolateyId
10
 * @package App\Models
11
 *
12
 * @property boolean mail_verified
13
 */
14
class ChocolateyId extends ChocolateyModel
15
{
16
    /**
17
     * Disable Timestamps.
18
     *
19
     * @var bool
20
     */
21
    public $timestamps = false;
22
23
    /**
24
     * The table associated with the model.
25
     *
26
     * @var string
27
     */
28
    protected $table = 'chocolatey_users_id';
29
30
    /**
31
     * Primary Key of the Table.
32
     *
33
     * @var string
34
     */
35
    protected $primaryKey = 'mail';
36
37
    /**
38
     * The Appender(s) of the Model.
39
     *
40
     * @var array
41
     */
42
    protected $appends = array('relatedAccounts');
43
44
    /**
45
     * The attributes that are mass assignable.
46
     *
47
     * @var array
48
     */
49
    protected $fillable = array('mail', 'password', 'last_logged_id', 'mail_verified');
50
51
    /**
52
     * Store a new Azure Id Account.
53
     *
54
     * @param string $userMail
55
     * @param string $userPassword
56
     * @return ChocolateyId
57
     */
58
    public function store(string $userMail, string $userPassword): ChocolateyId
59
    {
60
        $this->attributes['password'] = hash(Config::get('chocolatey.security.hash'), $userPassword);
61
        $this->attributes['mail'] = $userMail;
62
63
        $this->save();
64
65
        return $this;
66
    }
67
68
    /**
69
     * Get All Accounts related with this E-mail.
70
     *
71
     * @return Collection|static[]
72
     */
73
    public function getRelatedAccountsAttribute()
74
    {
75
        return User::query()->where('mail', $this->attributes['mail'])->get();
76
    }
77
}
78