assuming you have setup relation properly
Brand::with('customers')->where('fk_uid',$request->id)->get()->pluck(['brand','id']);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
create a form where I must, make a dynamic , and for that I execute this query that returns the data, but I think I could optimize this query with eloquent, some idea:
Brand::join("customers", "customers.fk_uid", "brands.fk_uid") ->where("brands.fk_uid", $request->id) ->pluck('brands.brand','brands.id')->all();
What is the point of getting customers at all in that query? It looks like all you're doing is getting the brand and id from the brands table by the brands.fk_uid, so why do you need to go through customers at all?
Brand::where('fk_uid', $request->id)->pluck('brand', 'id');
?
Please or to participate in this conversation.