You should have a OneToMany relation between Product and BrandOption
You can use intersect
https://laravel.com/docs/9.x/collections#method-intersect
$product_bo=...
$bos=...
$bos_available = $bos->intersect($produc-bo);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi All
I'm a little stuck on a join query and was wondering if i'm barking up the wrong tree. In my app i have brands and products. Brands have options & sub options which can then be assigned to the product options & sub options which are related to the product (to save having to re create the options etc for each product).
At the moment i've got it working and have assigned brand options & sub options to product A but when i go to product B its only showing the brand options that have been assigned to Product A and i think this is an issue with the join.
Here's what i've got:-
$brandOptions = \DB::table('brand_options')
->join('product_options', 'brand_options.id', '=', 'product_options.brand_option_id')
->select('brand_options.*', 'product_options.brand_option_id', 'product_options.product_id')
->where('product_options.brand_option_id', '!=', 'brand_options.id')
->where('brand_options.brand_id', $this->brand)
->where('product_options.product_id', '!=', $product)
->get();
But what i'm looking to do is to show all brand options that aren't assigned to that particular product on the product options table so that they can then be assigned.
Any questions, please let me know. Thanks in advance folks.
all brand options that aren't assigned to that particular product
all brand options
$bos=BrandOption::pluck('id')
don't understand why you filter by $this->brand in your code
product options
$product_bos=ProductOption::where('product_id', $this->pid)->pluck('brand_option_id');
all brand options that aren't assigned to that particular product
$bos_available = $bos->diff($product_bos);
Please or to participate in this conversation.