Php 雄辩的ORM:具有相同变量的类似查询

Php 雄辩的ORM:具有相同变量的类似查询,php,laravel,eloquent,Php,Laravel,Eloquent,是否有任何可能的方法来检索类似查询的结果使用雄辩?假设您希望first\u column在三个查询中是相同的值,但是second\u column在这些查询中是三个不同的值。 例如: 预期成果: 实际结果: 我遗漏了什么?是的,您需要完成每个查询。我知道你想做什么,我自己也试过了——而且在纸上应该行得通。但事实并非如此 因此,只需使用3个查询。没办法 $first = 'alwaysTheSame'; $second = [1,2,3]; $data1 = Model::where('f

是否有任何可能的方法来检索类似查询的结果使用雄辩?假设您希望
first\u column
在三个查询中是相同的值,但是
second\u column
在这些查询中是三个不同的值。

例如:


预期成果:


实际结果:



我遗漏了什么?

是的,您需要完成每个查询。我知道你想做什么,我自己也试过了——而且在纸上应该行得通。但事实并非如此

因此,只需使用3个查询。没办法

$first = 'alwaysTheSame';
$second = [1,2,3];
$data1 = Model::where('first', '=', $first)->where('second', '=', $second[0])->get();
 $data2 = Model::where('first', '=', $first)->where('second', '=', $second[1])->get();
 $data3 = Model::where('first', '=', $first)->where('second', '=', $second[2])->get();

快乐编码

我明白了。这是可以做到的,但您需要克隆
$query
。它还有助于将Laravel的
辅助功能一起用于链接:

$query = Model::where('first_column', '=', $something);

list($value, $diff_value, $another_diff_value) = [1, 2, 3];

// This is where I would like the results to diverge.
$one = with(clone($query))->where('second_column', '=', $value)->get();
$two = with(clone($query))->where('second_column', '=', $diff_value)->get();
$three = with(clone($query))->where('second_column', '=', $another_diff_value)->get();
如果
$query
是一个比示例中提供的查询更长的查询,那么这似乎很有用

$one | first_column | second_column |   $two | empty   $three | empty
-----+--------------+---------------+   
     |       1      |       1       |         
     |--------------|---------------|         
     |       1      |       1       |         
     |--------------|---------------|         
     |       1      |       1       |         
     |--------------|---------------|         
     |       1      |       1       |         
     |--------------|---------------|         
     |       1      |       1       |         
     --------------------------------   
$first = 'alwaysTheSame';
$second = [1,2,3];
$data1 = Model::where('first', '=', $first)->where('second', '=', $second[0])->get();
 $data2 = Model::where('first', '=', $first)->where('second', '=', $second[1])->get();
 $data3 = Model::where('first', '=', $first)->where('second', '=', $second[2])->get();
$query = Model::where('first_column', '=', $something);

list($value, $diff_value, $another_diff_value) = [1, 2, 3];

// This is where I would like the results to diverge.
$one = with(clone($query))->where('second_column', '=', $value)->get();
$two = with(clone($query))->where('second_column', '=', $diff_value)->get();
$three = with(clone($query))->where('second_column', '=', $another_diff_value)->get();