laravel - 如何验证 Laravel 请求中的选择

标签 laravel laravel-5 model-view-controller eloquent

我正在构建一个应用程序来创建足球比赛。当我创建比赛时,我需要检查所选球队是否属于所选联赛。

提交表单后,我想显示一条消息,表明选择了错误的联赛。

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/

相关文章:

java - 在java mvc中共享模型对象

java - 标签或页面片段中使用的 Spring-MVC 通用模型属性

model-view-controller - MVC : Am I doing it right?

laravel - 无法通过 Vue.js(Axios 帖子)从 Laravel 后端下载文件(pdf)

php - 如何修复Page Insights利用Google Cloud,Docker,Nginx和Laravel进行缓存?

Laravel env ('APP_URL' )没有返回 localhost 的正确值

php - 查询对象数组(带 JSONB 的 Postgres,Laravel 5)

php - 提供空白页且没有错误

mysql - Laravel wherebetween with orwherebetween

php - 在 Laravel 5.1 验证之前修改输入