jok3r

How get just id / name from relational model?

Posted 7 months 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.

Reply to

Use Markdown with GitHub-flavored code blocks.