Php 拉雷维尔有一个带where STATIONS的曼尼思酒店
我使用的是Laravel5.3,我试图使用Php 拉雷维尔有一个带where STATIONS的曼尼思酒店,php,laravel,eloquent,Php,Laravel,Eloquent,我使用的是Laravel5.3,我试图使用hasmanythrough与where语句的关系,但我不知道如何实现这个目标 所以我有这些表格: Users: +----+-------+ | id | name | +----+-------+ | 1 | James | +----+-------+ Orders: +----+---------+------------+ | id | user_id | state | +----+---------+------------
hasmanythrough
与where
语句的关系,但我不知道如何实现这个目标
所以我有这些表格:
Users:
+----+-------+
| id | name |
+----+-------+
| 1 | James |
+----+-------+
Orders:
+----+---------+------------+
| id | user_id | state |
+----+---------+------------+
| 1 | 1 | complete |
+----+---------+------------+
| 2 | 1 | incomplete |
+----+---------+------------+
| 3 | 1 | pending |
+----+---------+------------+
Order Items:
+----+----------+--------+
| id | order_id | name |
+----+----------+--------+
| 1 | 1 | Mac |
+----+----------+--------+
| 2 | 1 | Tablet |
+----+----------+--------+
| 3 | 2 | Laptop |
+----+----------+--------+
现在我想获取用户的订单项目,因此我将执行以下操作:
public function items()
{
$this-hasManyThrough(Item::class, Order::class)
}
但是!如果我只想取他们的订单声明为
complete
的项目,该怎么办?如果你想获取身份验证用户状态为complete
的所有项目,请使用以下方法:
不要忘记在项目中定义订单()
关系
模型:
public function order()
{
return $this->belongsTo(Order::class);
}
public function order()
{
return $this->belongsTo(Order::class);
}