Closed enaeim closed 6 years ago
I found the solution myself.
I use the filter method below :
`$grid->filter(function (Grid\Filter $filter) {
$filter->where(function ($query) {
$query->where('branch_product.product_id', "{$this->input}");
}, 'product')->select(Product::all()->pluck('name', 'id'));
$filter->where(function ($query) {
$query->where('branch_product.branch_id', "{$this->input}");
}, 'branch')->select(Branch::all()->pluck('name', 'id'));
});`
$filter->where(function ($query) {
$query->whereHas('branch_product', function($query){
$query->where('product_id', $this->input);
});
}, 'product')->select(Product::all()->pluck('name', 'id'));
work for me
Hi.
Description :
I use a join eloquent in grid and then I use filter method. But the filter doesn't work. I know that in the query below,
product_id
= 1 is incorrect andbranch_product
.product_id
= 1. But I don't know how to fix it in the filter method.Error :
QueryException In Connection.php line 664 : SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'product_id' in where clause is ambiguous (SQL: select count(*) as aggregate from
branch_product
inner joinbranch_product_stock
onbranch_product_stock
.id
=branch_product
.id
whereproduct_id
= 1)Tables :
branch_product table columns: id, branch_id, product_id branch_product_stock table columns: id, stock
Controller :
`class BranchProductController extends Controller {
}`
Thans for your help.