Alidnet's avatar

Get ID Array and use in second Query

I'm getting myself in a corner If anyone could assist please, I need to get an array of Area id's then use that array to show all the related properties of those areas.

Below is what i have so far.

       $areaass = AreaAss::where('areaid', $AreaIds)
        ->select('associd')
        ->get();

        $property = LeaseProperty::whereIn('areaid', [$areaass])
       // $property = LeaseProperty::whereIn('areaid', [63, 23, 30, 36, 37, 50, 61, 62, 320, 344])
        ->whereHas('unit', function ($query) {
        $query->where('tolet', '1')
        ->select('type', 'unitsize', 'rentprice', 'tolet', 'forsale');
        })       
        ->paginate(10);

0 likes
2 replies
drewdan's avatar

Do you not have a direct relation to the AreaAss model and the LeasePropery?

$areaass = AreaAss::where('areaid', $AreaIds)
       ->with('properties')
        ->select('associd')
        ->get();
Alidnet's avatar

this worked, thank you

        $areaass = AreaAss::where('areaid', $AreaIds)
        ->pluck('associd');

     
        $property = LeaseProperty::whereIn('areaid', $areaass)
       // $property = LeaseProperty::whereIn('areaid', [63, 23, 30, 36, 37, 50, 61, 62, 320, 344])
        ->whereHas('unit', function ($query) {
        $query->where('tolet', '1')
        ->select('type', 'unitsize', 'rentprice', 'tolet', 'forsale');
        })       
        ->paginate(10);
1 like

Please or to participate in this conversation.