我正在构建一个应用程序来创建足球比赛。当我创建比赛时,我需要检查所选球队是否属于所选联赛。
提交表单后,我想显示一条消息,表明选择了错误的联赛。
Controller 中有store()
方法
$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;
团队模型:
class Team extends Model
{
public function league() {
return $this->belongsTo('App\League');
}
}
联赛模式:
class League extends Model
{
public function teams() {
return $this->hasMany('App\Team');
}
}
最佳答案
这是 Laravel docs关于验证
关于laravel - 如何验证 Laravel 请求中的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66356136/