Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
www
/
admin
/
app
/
Models
/
Filename :
Group.php
back
Copy
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Casts\Attribute; use Config; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOne; class Group extends Model { use SoftDeletes; protected $table = 'groups'; protected $primaryKey = 'group_id'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'uuid', 'owner_user_id', 'team_id', 'group_name', 'group_image', 'country_id', 'created_at', 'updated_at', 'deleted_at' ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'deleted_at' ]; protected function groupImage(): Attribute { return Attribute::make( get: function (? string $value) { if(empty($value)){ return Config::get('constants.app.api-group-image-url').'default-group-image-color.jpg'; } return Config::get('constants.app.api-group-image-url').$value; } ); } /** * Get the members for the group. */ public function members(): HasMany { return $this->hasMany('App\Models\GroupMember', 'group_id'); } public function pending_invitations(): HasMany { return $this->hasMany('App\Models\GroupMember', 'group_id') ->whereNULL('invitation_accepted'); } public function active_members(): HasMany { return $this->hasMany('App\Models\GroupMember', 'group_id') ->whereNotNull('member_user_id')->where('invitation_accepted', true); } public function tasks(): HasMany{ return $this->hasMany('App\Models\Task', 'group_id', 'group_id'); } public function team(): HasOne{ return $this->hasOne('App\Models\Team', 'id', 'team_id'); } public function owner(): HasOne { return $this->hasOne('App\Models\User', 'user_id', 'owner_user_id'); } public function parents() { return $this->members() ->whereNotNull('member_user_id') ->where('invitation_accepted', true) ->whereHas('role', function ($query) { $query->whereIn('name', ['PARENT', 'SOCIAL_WORKER']); }) ->with('user') ->get() ->pluck('user'); } public function children(){ return $this->members() ->whereNotNull('member_user_id') ->where('invitation_accepted', true) ->whereHas('role', function ($query) { $query->whereIn('name', ['CHILD']); }) ->with('user') ->get() ->pluck('user'); } public function country(): HasOne { return $this->hasOne('App\Models\Country', 'country_id', 'country_id'); } }