|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
|
6
|
|
|
use Illuminate\Notifications\Notifiable; |
|
7
|
|
|
|
|
8
|
|
|
class User extends Authenticatable |
|
9
|
|
|
{ |
|
10
|
|
|
use Notifiable; |
|
11
|
|
|
|
|
12
|
|
|
private $defaultLocale = 'en_US'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The attributes that are mass assignable. |
|
16
|
|
|
* |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $fillable = [ |
|
20
|
|
|
'name', 'email', 'password', 'mmex_guid', |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The attributes that should be hidden for arrays. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $hidden = [ |
|
29
|
|
|
'password', 'remember_token', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
public function isAdmin() |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->attributes['is_admin']; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getLocaleAttribute() |
|
38
|
|
|
{ |
|
39
|
|
|
$locale = $this->attributes['locale'] ?? $this->defaultLocale; |
|
40
|
|
|
|
|
41
|
|
|
return $locale; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getLocaleKendoAttribute() |
|
45
|
|
|
{ |
|
46
|
|
|
$locale = $this->locale; |
|
47
|
|
|
|
|
48
|
|
|
$locale = str_replace('_', '-', $locale); |
|
49
|
|
|
|
|
50
|
|
|
return $locale; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getLocaleMomentAttribute() |
|
54
|
|
|
{ |
|
55
|
|
|
$locale = $this->locale; |
|
56
|
|
|
|
|
57
|
|
|
$locale = str_replace('_', '-', $locale); |
|
58
|
|
|
$locale = strtolower($locale); |
|
59
|
|
|
|
|
60
|
|
|
// TODO: ugly workaround for different locale styles |
|
61
|
|
|
$locale = $locale == 'de-de' ? 'de' : $locale; |
|
62
|
|
|
$locale = $locale == 'en-us' ? 'en' : $locale; |
|
63
|
|
|
|
|
64
|
|
|
return $locale; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getLanguageAttribute() |
|
68
|
|
|
{ |
|
69
|
|
|
$locale = $this->locale; |
|
70
|
|
|
$language = explode('_', $locale)[0]; |
|
71
|
|
|
|
|
72
|
|
|
return $language; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getApiTokenAttribute($value) |
|
76
|
|
|
{ |
|
77
|
|
|
if (empty($value)) { |
|
78
|
|
|
$value = str_random(60); |
|
79
|
|
|
$this->api_token = $value; |
|
80
|
|
|
$this->save(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $value; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
88
|
|
|
*/ |
|
89
|
|
|
public function transactions() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->hasMany(Transaction::class); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
96
|
|
|
*/ |
|
97
|
|
|
public function accounts() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->hasMany(Account::class); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
104
|
|
|
*/ |
|
105
|
|
|
public function payees() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->hasMany(Payee::class); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
112
|
|
|
*/ |
|
113
|
|
|
public function categories() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->hasMany(Category::class); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|