lagdo /
tontine
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Siak\Tontine\Model; |
||
| 4 | |||
| 5 | use Database\Factories\GuildFactory; |
||
| 6 | use Illuminate\Database\Eloquent\Builder; |
||
| 7 | use Illuminate\Database\Eloquent\Casts\Attribute; |
||
| 8 | use Illuminate\Database\Eloquent\Factories\Factory; |
||
| 9 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
||
| 10 | |||
| 11 | class Guild extends Base |
||
| 12 | { |
||
| 13 | use HasFactory; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 14 | use Traits\HasProperty; |
||
|
0 ignored issues
–
show
|
|||
| 15 | |||
| 16 | /** |
||
| 17 | * True if the guild is accessed as guest. |
||
| 18 | * |
||
| 19 | * @var bool |
||
| 20 | */ |
||
| 21 | public $isGuest = false; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The attributes that are mass assignable. |
||
| 25 | * |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | protected $fillable = [ |
||
| 29 | 'name', |
||
| 30 | 'shortname', |
||
| 31 | 'biography', |
||
| 32 | 'email', |
||
| 33 | 'phone', |
||
| 34 | 'address', |
||
| 35 | 'city', |
||
| 36 | 'website', |
||
| 37 | 'country_code', |
||
| 38 | 'currency_code', |
||
| 39 | ]; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return Attribute |
||
| 43 | */ |
||
| 44 | protected function locale(): Attribute |
||
| 45 | { |
||
| 46 | return Attribute::make( |
||
| 47 | get: fn() => $this->user->locale, |
||
|
0 ignored issues
–
show
|
|||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Create a new factory instance for the model. |
||
| 53 | * |
||
| 54 | * @return Factory |
||
| 55 | */ |
||
| 56 | protected static function newFactory() |
||
| 57 | { |
||
| 58 | return GuildFactory::new(); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function user() |
||
| 62 | { |
||
| 63 | return $this->belongsTo(User::class); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function members() |
||
| 67 | { |
||
| 68 | return $this->hasMany(MemberDef::class); |
||
| 69 | } |
||
| 70 | |||
| 71 | public function rounds() |
||
| 72 | { |
||
| 73 | return $this->hasMany(Round::class); |
||
| 74 | } |
||
| 75 | |||
| 76 | public function sessions() |
||
| 77 | { |
||
| 78 | return $this->hasManyThrough(Session::class, Round::class) |
||
| 79 | ->select('sessions.*'); |
||
| 80 | } |
||
| 81 | |||
| 82 | public function pools() |
||
| 83 | { |
||
| 84 | return $this->hasMany(PoolDef::class); |
||
| 85 | } |
||
| 86 | |||
| 87 | public function funds() |
||
| 88 | { |
||
| 89 | return $this->hasMany(FundDef::class); |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Get the default savings fund. |
||
| 94 | */ |
||
| 95 | public function default_fund() |
||
| 96 | { |
||
| 97 | return $this->hasOne(FundDef::class) |
||
| 98 | ->ofMany(['id' => 'max'], fn(Builder $query) => $query->auto()); |
||
| 99 | } |
||
| 100 | |||
| 101 | public function charges() |
||
| 102 | { |
||
| 103 | return $this->hasMany(ChargeDef::class); |
||
| 104 | } |
||
| 105 | |||
| 106 | public function categories() |
||
| 107 | { |
||
| 108 | return $this->hasMany(Category::class); |
||
| 109 | } |
||
| 110 | |||
| 111 | public function invites() |
||
| 112 | { |
||
| 113 | return $this->belongsToMany(GuestInvite::class, |
||
| 114 | 'guest_options', 'guild_id', 'invite_id') |
||
| 115 | ->as('options') |
||
| 116 | ->withPivot('access') |
||
| 117 | ->using(GuestOptions::class); |
||
| 118 | } |
||
| 119 | } |
||
| 120 |