I am trying to grab all records where Player's relationship called stats() has a column value of something. I would usually do ::where('column_name' 'column_value') for the players table, but how can I get ::where the relationship table's column equals to something?

Player::where('column_name', 'column_value')->get();

但是我想判断关系表中的一列吗?

public function roleplay()
{
    return $this->hasOne('App\Database\Frontend\User\Roleplay', 'user_id', 'id');
}

推荐答案

This will filter Player based on a related table

Player::whereHas('roleplay', function($q){
   $q->where('column_name', 'value');
})->get();

Laravel相关问答推荐

Laravel REST API:如何将数据库列名与参数的另一个名称映射?

无法使用 Dompdf Laravel 9 加载图像

阻止用户查看其他用户正在查看的内容的最佳方法是什么?

laravel 如何验证跨越午夜的两个值之间的时间(15:00 > 时间 > 01:00)

如何通过 Controller 访问 Laravel 中 Model 的值?

如何在自引用表上使用 Laravel 的 hasManyThrough

在 laravel 项目中放置 css 文件的位置

Lumen和 MongoDB?

在 laravel 的集合中找到?例子

在 laravel 中更改时区

如何在同一行显示 Laravel artisan 命令输出?

Laravel 从现有模型生成迁移

如何在 Laravel 中实现自己的 Faker 提供程序

我如何从给定的日期时间 struct 创建Carbon 对象?

Laravel:验证 json 对象

如何从 Laravel 中的资源中获取图像?

如何在 Laravel 或 Redis 中取消排队的作业(job)

配置和测试 Laravel 任务调度

Laravel 手动登录功能

错误:找不到模块 'webpack/lib/rules/DescriptionDataMatcherRulePlugin' 需要堆栈: