我的模型按以下方式设置:
Product
hasMany
ProductOption
和ProductOption
belongsTo
一个Option
。
我正在尝试查询Product
个ProductOption
个,这些Option
属于Oversized Shipping
个,其名称中不包含字符串Product::whereHas('productOptions', function($q) {
$q->whereHas('option', function($q) {
$q->where('name', 'not like', '%Oversized Shipping%');
});
})
->get();
这是我到目前为止所做的:
ProductOption
如何添加必须至少有两个有效 //calulating start date
$date = new DateTime(date("Y-m-d"));
$date->sub(new DateInterval('P1D'));
//Adding Dimensions
$params = array('dimensions' => 'ga:userType');
// requesting the data
$data = $service->data_ga->get("ga:xxxxxxxx", $date->format('Y-m-d'), date("Y-m-d"), "ga:users,ga:sessions", $params );
?><html>
<?php echo $date->format('Y-m-d') . " - ".date("Y-m-d"). "\n";?>
<table>
<tr>
<?php
//Printing column headers
foreach($data->getColumnHeaders() as $header){
print "<td>".$header['name']."</td>";
}
?>
</tr>
<?php
//printing each row.
foreach ($data->getRows() as $row) {
print "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td></tr>";
}
//printing the total number of rows
?>
<tr><td colspan="2">Rows Returned <?php print $data->getTotalResults();?> </td></tr>
</table>
</html>
<?php
?>
s?
答案 0 :(得分:1)
whereHas
方法takes additional arguments just for this:
$products = Product::whereHas('productOptions', function ($q) {
$q->whereHas('option', function ($q) {
$q->where('name', 'not like', '%Oversized Shipping%');
});
}, '>=', 2)->get();