Reputation: 806
Controller
$getFurniture = Furniture::where('active', 1)->pluck('fur_name', 'id');
dump($getFurniture);
Table
As you can see, the codes return all the value from the "furnitures" table, how do I eliminate the value that contain from "furniture_prices" table in the pluck queries result? So in this case, user can select "fur5", "fur6", "fur8", "fur9", "fur10", "fur11" and fur12"
Upvotes: 4
Views: 229
Reputation: 163768
I assume you already have the relationship defined. Use the doesntHave()
method:
Furniture::where('active', 1)->doesntHave('furniturePrices')->pluck('fur_name', 'id');
If the relationship doesn't exist yet, create hasOne()
or hasMany()
relationship first:
public function furniturePrices()
{
return $this->hasMany(FurniturePrice::class, 'fur_id');
}
Upvotes: 2