init commit
This commit is contained in:
commit
c9d982669a
461 changed files with 30317 additions and 0 deletions
70
app/Models/Team.php
Normal file
70
app/Models/Team.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Team extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'logo',
|
||||
'nb_players',
|
||||
'contact_email',
|
||||
'contact_phone',
|
||||
'status',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the competitions this team is participating in.
|
||||
*/
|
||||
public function competitions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Competition::class)
|
||||
->withTimestamps()
|
||||
->withPivot('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the matches where this team is the home team.
|
||||
*/
|
||||
public function homeMatches(): HasMany
|
||||
{
|
||||
return $this->hasMany(MatchGame::class, 'home_team_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the matches where this team is the away team.
|
||||
*/
|
||||
public function awayMatches(): HasMany
|
||||
{
|
||||
return $this->hasMany(MatchGame::class, 'away_team_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all matches for this team (both home and away).
|
||||
*/
|
||||
public function matches()
|
||||
{
|
||||
return $this->homeMatches->merge($this->awayMatches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the break periods assigned to this team.
|
||||
*/
|
||||
public function breakPeriods(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(BreakPeriod::class)
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue