2 months ago

Collections - Filter child relationship if field is null

Posted 2 months ago by belipero

Hi! I have a controller method that returns a model with it's relationships (1:M) All child records are returned but I want to don't reterieve child record from a particular model which has a null field.

I'm trying to use whereNotNull for filtering the child table column but it looks i'm not passing correctly the refernce to it: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'attributes.pa_value' in 'where clause'

How can I not retrieve those child records which has a null value in a column?


class PropertyController extends Controller
    public function details($id)
        $property = Property::with('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
                    ->where('prop_id', $id)
                  //  ->whereNotNull('attributes.pa_value')
                    ->withCount('attributes', 'addons', 'distributions', 'images', 'attributes_2', 'services')
        return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));


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