Published 9 months ago by johnvoncolln
I've got a website that sells products. I have retail customers and wholesale customers that I can assign unique pricing to on a per product basis. I have a pricing scheme table that has fields for each product id with the value being the prices. I associate a pricing to a customer via a pivot table. There's some logic that states if a price for a specific product isn't found for this user's pricing scheme, then use the default pricing scheme. This way I can also only change some products, and leave the rest default.
Is there a better way? It's a bit clunky and right now there's no logic to add fields to the pricing scheme if a new product is added. Looking for a better way.
Laravel has a when
keyword, look for some examples of that.
I've been searching and haven't found anything! Do you have any examples or links?
My latest thought was to have a group pricing table associated to the product table, so you could assign a price associated with a group, per product.
@johnvoncolln I think @jlrdw is refering to this
when()
The when
method will execute the given callback when the first argument given to the method evaluates to true
:
$collection = collect([1, 2, 3]);
$collection->when(true, function ($collection) {
return $collection->push(4);
});
$collection->all();
// [1, 2, 3, 4]
It's new to me, so it may not apply to queries, but a collection: https://laravel.com/docs/5.4/collections#method-when
on one post I saw when used to do one query when one condition was met and another query if another condition, but sorry I did not bookmark that one.
Please sign in or create an account to participate in this conversation.