87 lines
2.1 KiB
PHP
87 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Member;
|
|
|
|
use App\Activity;
|
|
use App\Nami\HasNamiField;
|
|
use App\Subactivity;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* @property int $count
|
|
*/
|
|
class Membership extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasNamiField;
|
|
|
|
/** @var array<int, string> */
|
|
public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from', 'to', 'promised_at'];
|
|
|
|
/** @var array<string, string> */
|
|
public $casts = [
|
|
'from' => 'date',
|
|
'to' => 'date',
|
|
'promised_at' => 'date',
|
|
];
|
|
|
|
/**
|
|
* @return BelongsTo<Activity, self>
|
|
*/
|
|
public function activity(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Activity::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Subactivity, self>
|
|
*/
|
|
public function subactivity(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Subactivity::class);
|
|
}
|
|
|
|
/**
|
|
* @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));
|
|
}
|
|
}
|