Support the ongoing development of Laravel.io →
Eloquent Laravel Database
Last updated 1 year ago.
0

Hi Nima,

Get the results first and then pluck the field from the collection. So like this:

$Result = TableA::with('tableB')
    ->where('fieldA', $valueA)->whereHas('tableB', function($query){
    // Now querying on tableB
    $query->where('fieldB', $valueB);
})->get()->pluck('fieldB')->toArray();

This will use the collection's pluck method, not the query builder's. I don't know if that's what you're looking for, but I assume it'll work just as well.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Nima webcoweb Joined 14 Aug 2018

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.