- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个模型:
STAFF
-----
id
name
PAGE_STAFF
----------
page_id
staff_id
PAGE
----
id
title
parent_id
PARENT_PAGE
-----------
id
title
像这样的关系方法:
in Staff Model
/**
* The areas that belongs to the staff member.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function pages()
{
return $this->belongsToMany(Page::class);
}
in Page Model
/**
* The staff that belongs to the page.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function staff()
{
return $this->belongsToMany(Staff::class);
}
PARENT_PAGE 包含“主页”的 id(和标题)。该模型不与任何模型连接,我用它来过滤事件。我的意思是我只需要 page_staff 中的 page_id,parent_page.id == page_staff.page_id。
但我需要知道数据透视表“page_staff”中的条目。需要的查询是
“page_staff”模型中包含的所有工作人员 (page_staff.staff_id) 且 page_staff.page_id == Parent_page.id。
此后我需要所有员工模型(staff.id)
如何在 Eloquent 中执行此操作?
致以诚挚的问候
最佳答案
对 ParentPage 在这一切中如何连接有点困惑。要获取数据透视表中的所有人员,我们可以使用 has()
来完成。当我知道父页面在此域中的位置时,将更新问题。
$staffWithPages = Staff::whereHas('pages.parent', function ($query) {
$query->where('laravel_reserved_0.id', '!=', 'page_staff.page_id');
})->get();
如果您想要 id,请使用 Laravel Collection
pluck 方法。
$staffWithPages->plukc('id')->all();
关于php - 查询获取人员相关(数据透视表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56964775/
是否有用于手动测试的代码覆盖工具?比如我新写了30行代码,编译,然后运行,有什么办法可以快速验证这30行都运行了吗? 另外,后来,在我将代码 checkin 正式版本后,有什么方法可以验证测试部门在进
老实说,这是一个家庭作业问题,但我已经浪费了好几个小时,而且无法正确解决。它返回错误数量的结果或错误的数据: 我需要选择参与指导电影和/或在电影中表演的每个人以及他们所做的次数,如果至少 5 次。 有
我正在尝试测试 MacOS 的应用内购买。输入测试用户凭据后,App Store 提示:“当前收据无效或 ds 人员 ID 不匹配。”并且购买失败。 最佳答案 我尝试了很多方法来解决这个问题。 Get
我正在为 Jenkins 使用 ActiveDirectory 插件,因此用户必须使用他们的凭据登录到 Jenkins。然后用户在 Jenkins 中被称为 joe.doe,这很完美。 当同一个人 c
如何从 Infopath 人员/组选取器检索电子邮件地址?当我将人员/组选取器添加到 infopath 表单时,我只得到 3 个字段 DisplayName、AccountId、AccountType
在 Snow Leopard 中,可以在 iCal 事件中显示空闲/忙碌时间。我搜索了 CalStore.framework 的 header ,但找不到任何描述该字段的属性。如何检索日历事件的忙/闲
是否有人成功地从专门针对 SharePoint 2013 的新建或编辑表单中获取用户(个人或组)字段的值? 我已经尝试了通过搜索互联网找到的所有解决方案以及我自己能想到的所有解决方案,所有结果都为空白
所以我需要将一个 Twitter 帐户添加到 ABRecordRef 中。然而,最快的方法似乎是获取社交资料属性的多值引用,创建它的可变版本,查找它是否有 Twitter 条目,如果已经有,则创建
我正在尝试将使用 Tomcat(最初是 5.5,但可以与 7 一起使用)在 MyEclipse 中开发的应用程序部署到我们的演示服务器 (Sun Java Web Server 7)。不幸的是,所有设
我是一名优秀的程序员,十分优秀!