Hi,
I have tables of franchise productsproduct_special_prices
All products are stored in a product table with their price and details. But things get tricky when I set the product's special price.
For setting special prices I am using the product_special_price table in that table I am storing
product_id , franchse_id, price
The reason why I am doing this is all products are listed in every franchise but if the admin wants to set a special price of the product for any franchise then this solution will work, now the problem is app developer wants me to send all products with their detail and price if the product has special price than it should show a special price else normal price will show in API wile time of fetching data.
How can I do this in my controller?
Currently, I am sending products like below
@sr57 Thanks for the reply,
yes I defined but the relationship is with product and product_special_price and that is Product->hasMnay(SpecialPrice::class)
and your second question is about no need to have franchise_id why did I set it up because. In my case, one table is the franchise and the second is a product, when I create any product its means when a user opens any franchise he will be able to see all products.
For example:
I have products A with a price of 10 Rs and B with a price of 20 Rs and the franchises are KFC & McDonald. now if the user opens KFC or McDonald it will see product A with 10 Rs & B with 20 Rs. Now system admin wants to set a special price for product B for KFC the default price is 20 Rs, but he wants when someone opens KFC the product B price will show 30 Rs instead of 20. This is my whole scenario hope you understand
@sr57 I have tried one more method and this almost works for me please guide me how can i get out form this
I want to pass an additional parameter to the resource,
I have passed franchise_id to my resource collection now how can I get it in my resource array?