You can try the following:
$value = 'someName'; Project::with(['clients', 'tasks', 'status' => function($q) use($value) { // Query the name field in status table $q->where('name', '=', $value); // '=' is optional }]) ->where('status_id', '!=', '2') ->whereUserId(Auth::user()->id) ->get();
You can also try this (it will retrieve records only if query returns name , otherwise not):
$value = 'someName'; Project::with(['clients', 'tasks', 'status']) ->whereHas('status', function($q) use($value) { // Query the name field in status table $q->where('name', '=', $value); // '=' is optional }) ->where('status_id', '!=', '2') ->whereUserId(Auth::user()->id) ->get();
source share