I am building an app to create Football (Soccer) matches. When I create a match, I need to check that the selected teams are in the chosen league.
When the form is submitted I would like to display a message that the wrong league selected if so.
There is store() method in controller
$match = new Match;
$match->round = $request->round;
$match->league_id = $request->league;
$match->home_team_id = $request->home_team;
$match->away_team_id = $request->away_team;
$match->match_date = $request->match_date;
$match->location = $request->location;
Team model:
class Team extends Model
{
public function league() {
return $this->belongsTo('App\League');
}
}
League model:
class League extends Model
{
public function teams() {
return $this->hasMany('App\Team');
}
}