|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FaithGen\SDK\Models; |
|
4
|
|
|
|
|
5
|
|
|
use FaithGen\SDK\Traits\Relationships\Has\ManyMinistryUsers; |
|
6
|
|
|
use FaithGen\SDK\Traits\Relationships\Morphs\CreatableTrait; |
|
7
|
|
|
use FaithGen\SDK\Traits\Relationships\Morphs\ImageableTrait; |
|
8
|
|
|
use FaithGen\SDK\Traits\StorageTrait; |
|
9
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
|
10
|
|
|
use Illuminate\Notifications\Notifiable; |
|
11
|
|
|
|
|
12
|
|
|
class User extends Authenticatable |
|
13
|
|
|
{ |
|
14
|
|
|
use ManyMinistryUsers; |
|
15
|
|
|
use CreatableTrait; |
|
16
|
|
|
use Notifiable; |
|
|
|
|
|
|
17
|
|
|
use ImageableTrait; |
|
18
|
|
|
use StorageTrait; |
|
19
|
|
|
|
|
20
|
|
|
protected $table = 'fg_users'; |
|
21
|
|
|
protected $guarded = ['id']; |
|
22
|
|
|
public $incrementing = false; |
|
23
|
|
|
protected $hidden = [ |
|
24
|
|
|
'password', |
|
25
|
|
|
'created_at', |
|
26
|
|
|
'updated_at', |
|
27
|
|
|
'remember_token', |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
//****************************************************************************// |
|
31
|
|
|
//***************************** MODEL ATTRIBUTES *****************************// |
|
32
|
|
|
//****************************************************************************// |
|
33
|
|
|
|
|
34
|
|
|
public function getNameAttribute($val) |
|
35
|
|
|
{ |
|
36
|
|
|
return ucwords($val); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
//****************************************************************************// |
|
40
|
|
|
//***************************** MODEL RELATIONSHIPS *****************************// |
|
41
|
|
|
//****************************************************************************// |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Links comments to this user. |
|
45
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
46
|
|
|
*/ |
|
47
|
|
|
public function comments() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->hasMany(Comment::class); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getMinistriesAttribute() |
|
53
|
|
|
{ |
|
54
|
|
|
return Ministry::whereHas('ministryUsers', function ($minUser) { |
|
55
|
|
|
return $minUser->where('user_id', $this->id); |
|
56
|
|
|
}); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getActiveAttribute(): bool |
|
60
|
|
|
{ |
|
61
|
|
|
if ($user = $this->ministryUsers()->where('ministry_id', auth()->user()->id)->first()) { |
|
62
|
|
|
return (bool) $user->active; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
public function filesDir() |
|
72
|
|
|
{ |
|
73
|
|
|
return 'users'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getFileName() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->image->name; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getImageDimensions() |
|
82
|
|
|
{ |
|
83
|
|
|
return [0, 50]; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|