Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉雷维尔有一个带where STATIONS的曼尼思酒店_Php_Laravel_Eloquent - Fatal编程技术网

Php 拉雷维尔有一个带where STATIONS的曼尼思酒店

Php 拉雷维尔有一个带where STATIONS的曼尼思酒店,php,laravel,eloquent,Php,Laravel,Eloquent,我使用的是Laravel5.3,我试图使用hasmanythrough与where语句的关系,但我不知道如何实现这个目标 所以我有这些表格: Users: +----+-------+ | id | name | +----+-------+ | 1 | James | +----+-------+ Orders: +----+---------+------------+ | id | user_id | state | +----+---------+------------

我使用的是Laravel5.3,我试图使用
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);
}