adrema/app/Member/Membership.php

71 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2021-06-24 23:48:08 +02:00
<?php
namespace App\Member;
2021-08-22 22:23:17 +02:00
use App\Activity;
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;
2022-01-03 10:33:48 +01:00
public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from'];
2021-08-22 22:23:17 +02:00
public function activity(): BelongsTo
{
return $this->belongsTo(Activity::class);
}
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
}