blob: 38d58d8f7480b780d120b08600d22469db657954 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
<?php
namespace App\Rugby\Model;
use Illuminate\Database\Eloquent\Model;
class Match extends Model
{
protected $table = 'matches';
protected $casts = ['date' => 'datetime:Y-m-d'];
protected $fillable = ['score', 'half_score', 'referee', 'date'];
public function teams()
{
return $this->belongsToMany(Team::class, 'match_team');
}
public function venue()
{
return $this->hasOne(Venue::class, 'id');
}
public function getDisplayName()
{
$venue = Venue::find($this->venue_id);
if (!$venue) {
return 'Unknown';
}
return $venue->name;
}
public function getDisplayDate()
{
return (new \Carbon\Carbon($this->date))->format('M d Y');
}
public function getVideoUrl()
{
$video = $this->videos()->first();
if (! $video) {
return '';
}
return $video->getUrl();
}
public function getHomeTeam()
{
return $this->teams()->wherePivot('is_home', '=', true)->first();
}
public function getAwayTeam()
{
return $this->teams()->wherePivot('is_home', '=', false)->first();
}
public function tournaments()
{
return $this->belongsToMany(Tournament::class, 'match_tournament');
}
public function videos()
{
return $this->hasMany(Video::class, 'match_id');
}
}
|