How get just id / name from relational model?

Posted 1 month ago by jok3r

Hi, i'm n00b with laravel, and eloquent is awesome, but i don't know how make somethings.

make Customer model and Brand model in Customer make brand ralation

public function brands() { return $this->hasMany(Brand::class, 'fk_uid', 'fk_uid'); }

And now want get only : $brands = Brand::pluck('brand', 'id'); for example...

But before need make a validation on Customer $customers = Customer::where('is_approved', '=', 'approved')->brands::pluck('id', 'brand')->get();

it's possible?

Thank you

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.