Support the ongoing development of Laravel.io →
Eloquent Laravel Database
Last updated 3 months 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!

LoadForge

Your banner here too?

Nima Nima webcoweb Joined 14 Aug 2018

Moderators

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

Your logo here?

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

© 2022 Laravel.io - All rights reserved.