Jun 16, 2020
0
Level 2
Larael Nova Filter Only Showing Single Items
Hi,
So i am working on some filters for a resource that i have for some Product PDFs we have in our system. I am able to filter by the product family, except it is only showing one product when it should be showing multiple? I have 3 tables that i have had to join together for this, the relationship is as follows:
ProductFamilyModel
public function product_pdf()
{
return $this->belongsToMany(ProductPdfModel::class, 'product_family_pdfs', 'product_family_id', 'product_pdfs_id');
}
ProductPDFModel
public function product_family_pdf()
{
return $this->hasMany(ProductFamilyPDFModel::class, 'product_pdfs_id');
}
ProductFamilyPDFModel
public function product_pdf()
{
return $this->belongsTo(ProductPdfModel::class, 'product_pdf_id');
}
In the Filter i have the following join to get the options:
public function apply(Request $request, $query, $value)
{
return $query->where("id", $value);
}
public function options(Request $request)
{
$options = [];
$items = DB::table('product_family_pdfs')
->join('product_pdfs', 'product_family_pdfs.product_pdfs_id', '=', 'product_pdfs.id')
->join('product_family', 'product_family_pdfs.product_family_id', '=', 'product_family.id')
->select('product_pdfs.id as id', 'product_family.product_name as product_family_name')
->get();
foreach ($items as $item) {
$options[$item->product_family_name] = $item->id;
}
return $options;
}
Please or to participate in this conversation.