faithgen /
laravel-sdk
| 1 | <?php |
||
| 2 | |||
| 3 | namespace FaithGen\SDK\Models; |
||
| 4 | |||
| 5 | use FaithGen\SDK\Models\Ministry\Account; |
||
| 6 | use FaithGen\SDK\Models\Ministry\Activation; |
||
| 7 | use FaithGen\SDK\Models\Ministry\APIKey; |
||
| 8 | use FaithGen\SDK\Models\Ministry\DailyService; |
||
| 9 | use FaithGen\SDK\Models\Ministry\Profile; |
||
| 10 | use FaithGen\SDK\Models\Ministry\Review; |
||
| 11 | use FaithGen\SDK\Traits\Relationships\Has\ManyMinistryUsers; |
||
| 12 | use FaithGen\SDK\Traits\Relationships\Morphs\CreatableTrait; |
||
| 13 | use FaithGen\SDK\Traits\Relationships\Morphs\ImageableTrait; |
||
| 14 | use FaithGen\SDK\Traits\StorageTrait; |
||
| 15 | use Illuminate\Foundation\Auth\User as Authenticatable; |
||
| 16 | use Illuminate\Notifications\Notifiable; |
||
| 17 | use Tymon\JWTAuth\Contracts\JWTSubject; |
||
| 18 | |||
| 19 | class Ministry extends Authenticatable implements JWTSubject |
||
| 20 | { |
||
| 21 | use Notifiable; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 22 | use ImageableTrait; |
||
| 23 | use StorageTrait; |
||
| 24 | use ManyMinistryUsers; |
||
| 25 | use CreatableTrait; |
||
| 26 | |||
| 27 | protected $table = 'fg_ministries'; |
||
| 28 | protected $guarded = ['id']; |
||
| 29 | public $incrementing = false; |
||
| 30 | protected $hidden = [ |
||
| 31 | 'password', |
||
| 32 | 'created_at', |
||
| 33 | 'updated_at', |
||
| 34 | ]; |
||
| 35 | |||
| 36 | public const ACCOUNT_LEVELS = ['Free', 'Premium', 'PremiumPlus']; |
||
| 37 | |||
| 38 | public function getJWTIdentifier() |
||
| 39 | { |
||
| 40 | return $this->getKey(); |
||
| 41 | } |
||
| 42 | |||
| 43 | public function getJWTCustomClaims() |
||
| 44 | { |
||
| 45 | return []; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * MODEL ATTRIBUTES. |
||
| 50 | */ |
||
| 51 | public function getNameAttribute($val) |
||
| 52 | { |
||
| 53 | return ucwords($val); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Links the profile to a ministry. |
||
| 58 | * |
||
| 59 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
| 60 | */ |
||
| 61 | |||
| 62 | /** |
||
| 63 | * MODEL RELATIONSHIPS. |
||
| 64 | */ |
||
| 65 | public function reviews() |
||
| 66 | { |
||
| 67 | return $this->hasMany(Review::class); |
||
| 68 | } |
||
| 69 | |||
| 70 | public function profile() |
||
| 71 | { |
||
| 72 | return $this->hasOne(Profile::class); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Links the account to the ministry. |
||
| 77 | * |
||
| 78 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
| 79 | */ |
||
| 80 | public function account() |
||
| 81 | { |
||
| 82 | return $this->hasOne(Account::class); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Links the activation to this ministry. |
||
| 87 | * |
||
| 88 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
| 89 | */ |
||
| 90 | public function activation() |
||
| 91 | { |
||
| 92 | return $this->hasOne(Activation::class); |
||
| 93 | } |
||
| 94 | |||
| 95 | public function apiKey() |
||
| 96 | { |
||
| 97 | return $this->hasOne(APIKey::class); |
||
| 98 | } |
||
| 99 | |||
| 100 | public function services() |
||
| 101 | { |
||
| 102 | return $this->hasMany(DailyService::class); |
||
| 103 | } |
||
| 104 | |||
| 105 | public function getPhonesAttribute() |
||
| 106 | { |
||
| 107 | if ($this->profile->phones) { |
||
|
0 ignored issues
–
show
The expression
$this->profile->phones of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 108 | $phones = $this->profile->phones; |
||
| 109 | array_unshift($phones, $this->phone); |
||
| 110 | |||
| 111 | return $phones; |
||
| 112 | } else { |
||
| 113 | return [$this->phone]; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | public function getEmailsAttribute() |
||
| 118 | { |
||
| 119 | if ($this->profile->emails) { |
||
|
0 ignored issues
–
show
The expression
$this->profile->emails of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 120 | $emails = $this->profile->emails; |
||
| 121 | array_unshift($emails, $this->email); |
||
| 122 | |||
| 123 | return $emails; |
||
| 124 | } else { |
||
| 125 | return [$this->email]; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * The name of the directory in storage that has files for this model. |
||
| 131 | * |
||
| 132 | * @return mixed |
||
| 133 | */ |
||
| 134 | public function filesDir() |
||
| 135 | { |
||
| 136 | return 'profile'; |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * The file name fo this model. |
||
| 141 | * |
||
| 142 | * @return mixed |
||
| 143 | */ |
||
| 144 | public function getFileName() |
||
| 145 | { |
||
| 146 | return $this->image->name; |
||
|
0 ignored issues
–
show
|
|||
| 147 | } |
||
| 148 | |||
| 149 | public function getUsersAttribute() |
||
| 150 | { |
||
| 151 | return $this->ministryUsers() |
||
| 152 | ->map(fn ($minUser) => $minUser->user) |
||
| 153 | ->flatten(); |
||
| 154 | } |
||
| 155 | } |
||
| 156 |