1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* LeagueMovie |
5
|
|
|
* |
6
|
|
|
* @property-read \League $league |
7
|
|
|
* @property-read \Movie $movie |
8
|
|
|
* @property-read \MovieEarning $latestEarnings |
9
|
|
|
* @property integer $id |
10
|
|
|
* @property integer $league_id |
11
|
|
|
* @property integer $movie_id |
12
|
|
|
* @property integer $price |
13
|
|
|
* @property integer $latest_earnings_id |
14
|
|
|
* @property \Carbon\Carbon $created_at |
15
|
|
|
* @property \Carbon\Carbon $updated_at |
16
|
|
|
* @method static \Illuminate\Database\Query\Builder|\LeagueMovie whereId($value) |
17
|
|
|
* @method static \Illuminate\Database\Query\Builder|\LeagueMovie whereLeagueId($value) |
18
|
|
|
* @method static \Illuminate\Database\Query\Builder|\LeagueMovie whereMovieId($value) |
19
|
|
|
* @method static \Illuminate\Database\Query\Builder|\LeagueMovie wherePrice($value) |
20
|
|
|
* @method static \Illuminate\Database\Query\Builder|\LeagueMovie whereLatestEarningsId($value) |
21
|
|
|
* @method static \Illuminate\Database\Query\Builder|\LeagueMovie whereCreatedAt($value) |
22
|
|
|
* @method static \Illuminate\Database\Query\Builder|\LeagueMovie whereUpdatedAt($value) |
23
|
|
|
* @method static \LeagueMovie ordered() |
24
|
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\LeagueTeam[] $teams |
25
|
|
|
*/ |
26
|
|
|
class LeagueMovie extends Eloquent { |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The attributes that are mass assignable. |
30
|
|
|
* |
31
|
|
|
* @type array |
32
|
|
|
*/ |
33
|
|
|
protected $fillable = ['league_id', 'movie_id', 'latest_earnings_id', 'price']; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The league this entry is in |
37
|
|
|
* |
38
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
39
|
|
|
*/ |
40
|
|
|
public function league() { |
41
|
|
|
return $this->belongsTo('League'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The movie this entry represents |
46
|
|
|
* |
47
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
48
|
|
|
*/ |
49
|
1 |
|
public function movie() { |
50
|
1 |
|
return $this->belongsTo('Movie'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Teams this movie is owned by |
55
|
|
|
* |
56
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
57
|
|
|
*/ |
58
|
|
|
public function teams() { |
59
|
|
|
return $this->belongsToMany('LeagueTeam', 'league_team_movies')->withTimestamps(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* The latest earning usable in the league context |
64
|
|
|
* |
65
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
66
|
|
|
*/ |
67
|
1 |
|
public function latestEarnings() { |
68
|
1 |
|
return $this->belongsTo('MovieEarning'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* All movie's earnings |
73
|
|
|
* |
74
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
75
|
|
|
*/ |
76
|
|
|
public function earnings() { |
77
|
|
|
return $this->hasMany('MovieEarning','movie_id','league_movie_id'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Order movies by the release date |
83
|
|
|
* |
84
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query |
85
|
|
|
*/ |
86
|
1 |
|
public function scopeOrdered(Illuminate\Database\Eloquent\Builder $query) { |
87
|
1 |
|
$query->join('movies', 'league_movies.movie_id', '=', 'movies.id'); |
88
|
1 |
|
$query->orderBy('movies.release', 'ASC'); |
89
|
1 |
|
$query->select('league_movies.*'); |
90
|
1 |
|
} |
91
|
|
|
|
92
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.