I have 3 tables:
products table -id - title - etc.
purchases table -id -code - etc.
purchase_products table -id - purchase_id - product_id -qty - etc.
My goal is to retrieve purchases of a single product. The following relationship doesn't work for me. Tried different approaches using belongsToMany
also doesn't work.
$this->hasManyThrough( Purchase::class, PurchaseProduct::class, 'purchase_id', 'product_id', 'id', 'id' );
In a simple way I can get all the purchased products by product_id and then retrieve the purchased items but I need a relationship to make it work in Laravel nova as I want to display the purchased items on the resource .
Product number
Purchase Mode