2021-06-24 23:48:08 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Member;
|
|
|
|
|
2021-08-22 22:23:17 +02:00
|
|
|
use App\Activity;
|
2023-02-17 11:43:08 +01:00
|
|
|
use App\Nami\HasNamiField;
|
2021-08-22 22:23:17 +02:00
|
|
|
use App\Subactivity;
|
2022-11-16 23:39:44 +01:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2021-06-24 23:48:08 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2021-08-22 22:23:17 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2021-06-24 23:48:08 +02:00
|
|
|
|
2022-11-16 23:39:44 +01:00
|
|
|
/**
|
|
|
|
* @property int $count
|
|
|
|
*/
|
2021-06-24 23:48:08 +02:00
|
|
|
class Membership extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
2023-02-17 11:43:08 +01:00
|
|
|
use HasNamiField;
|
2021-06-24 23:48:08 +02:00
|
|
|
|
2023-02-17 18:57:11 +01:00
|
|
|
/** @var array<int, string> */
|
2023-02-06 00:57:37 +01:00
|
|
|
public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from', 'to', 'promised_at'];
|
2021-08-22 22:23:17 +02:00
|
|
|
|
2023-02-17 18:57:11 +01:00
|
|
|
/** @var array<string, string> */
|
2022-12-14 15:49:12 +01:00
|
|
|
public $casts = [
|
2023-02-06 00:57:37 +01:00
|
|
|
'from' => 'date',
|
|
|
|
'to' => 'date',
|
2022-12-14 15:49:12 +01:00
|
|
|
'promised_at' => 'date',
|
|
|
|
];
|
|
|
|
|
2023-02-17 18:57:11 +01:00
|
|
|
/**
|
|
|
|
* @return BelongsTo<Activity, self>
|
|
|
|
*/
|
2021-08-22 22:23:17 +02:00
|
|
|
public function activity(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Activity::class);
|
|
|
|
}
|
|
|
|
|
2023-02-17 18:57:11 +01:00
|
|
|
/**
|
|
|
|
* @return BelongsTo<Subactivity, self>
|
|
|
|
*/
|
2021-08-22 22:23:17 +02:00
|
|
|
public function subactivity(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Subactivity::class);
|
|
|
|
}
|
2022-11-16 23:39:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Builder<Membership> $query
|
|
|
|
*
|
|
|
|
* @return Builder<Membership>
|
|
|
|
*/
|
|
|
|
public function scopeIsAgeGroup(Builder $query): Builder
|
|
|
|
{
|
|
|
|
return $query->whereHas('subactivity', fn ($builder) => $builder->where('is_age_group', true));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Builder<Membership> $query
|
|
|
|
*
|
|
|
|
* @return Builder<Membership>
|
|
|
|
*/
|
|
|
|
public function scopeIsMember(Builder $query): Builder
|
|
|
|
{
|
|
|
|
return $query->whereHas('activity', fn ($builder) => $builder->where('is_member', true));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Builder<Membership> $query
|
|
|
|
*
|
|
|
|
* @return Builder<Membership>
|
|
|
|
*/
|
|
|
|
public function scopeIsLeader(Builder $query): Builder
|
|
|
|
{
|
|
|
|
return $query->whereHas('activity', fn ($builder) => $builder->where('has_efz', true));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Builder<Membership> $query
|
|
|
|
*
|
|
|
|
* @return Builder<Membership>
|
|
|
|
*/
|
|
|
|
public function scopeTrying(Builder $query): Builder
|
|
|
|
{
|
|
|
|
return $query->whereHas('activity', fn ($builder) => $builder->where('is_try', true));
|
|
|
|
}
|
2021-06-24 23:48:08 +02:00
|
|
|
}
|