-
Notifications
You must be signed in to change notification settings - Fork 554
/
User.php
97 lines (78 loc) · 2.09 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace A17\Twill\Models;
use A17\Twill\Models\Behaviors\HasMedias;
use A17\Twill\Models\Enums\UserRole;
use A17\Twill\Notifications\Reset as ResetNotification;
use A17\Twill\Notifications\Welcome as WelcomeNotification;
use Illuminate\Auth\Authenticatable;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Foundation\Auth\User as AuthenticatableContract;
use Illuminate\Notifications\Notifiable;
use Session;
class User extends AuthenticatableContract
{
use Authenticatable, Authorizable, HasMedias, Notifiable;
public $timestamps = true;
protected $fillable = [
'email',
'name',
'role',
'published',
'password',
];
protected $dates = [
'deleted_at',
];
protected $hidden = ['password', 'remember_token'];
public $checkboxes = ['published'];
public $mediasParams = [
'profile' => [
'default' => [
'name' => 'default',
'ratio' => 1,
],
],
];
public function getTitleInBrowserAttribute()
{
return $this->name;
}
public function getRoleValueAttribute()
{
if (!empty($this->role)) {
if ($this->role == 'SUPERADMIN') {
return "SUPERADMIN";
}
return UserRole::{$this->role}()->getValue();
}
return null;
}
public function scopePublished($query)
{
return $query->wherePublished(true);
}
public function scopeDraft($query)
{
return $query->wherePublished(false);
}
public function setImpersonating($id)
{
Session::put('impersonate', $id);
}
public function stopImpersonating()
{
Session::forget('impersonate');
}
public function isImpersonating()
{
return Session::has('impersonate');
}
public function sendWelcomeNotification($token)
{
$this->notify(new WelcomeNotification($token));
}
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetNotification($token));
}
}