- Fix: Notifiable-Trait zum User-Model hinzugefuegt (behebt notify()-500er) - Installer: SMTP-Verbindungstest mit EsmtpTransport + Ueberspringen-Link - Admin: Neuer E-Mail-Tab mit SMTP-Konfiguration + Verbindungstest - Admin: Lazy Quill-Initialisierung (nur sichtbare Locale wird geladen) - Uebersetzungen: 17 neue Mail-Keys in allen 6 Sprachen Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
1.5 KiB
PHP
Executable File
68 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\UserRole;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class Team extends Model
|
|
{
|
|
protected $fillable = [
|
|
'name',
|
|
'year_group',
|
|
'is_active',
|
|
'notes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function players(): HasMany
|
|
{
|
|
return $this->hasMany(Player::class);
|
|
}
|
|
|
|
public function events(): HasMany
|
|
{
|
|
return $this->hasMany(Event::class);
|
|
}
|
|
|
|
public function activePlayers(): HasMany
|
|
{
|
|
return $this->hasMany(Player::class)->where('is_active', true);
|
|
}
|
|
|
|
public function coaches(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class, 'team_user')
|
|
->withPivot('created_at');
|
|
}
|
|
|
|
public function files(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(File::class, 'team_file')
|
|
->withPivot('created_at');
|
|
}
|
|
|
|
public function parentReps(): Collection
|
|
{
|
|
return User::where('role', UserRole::ParentRep)
|
|
->where('is_active', true)
|
|
->whereHas('children', fn ($q) => $q->where('team_id', $this->id))
|
|
->orderBy('name')
|
|
->get();
|
|
}
|
|
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
}
|