Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RushVan's avatar

Query builder 'where does not exist'?

I am try to do this;

select records from table where value A does not exist in table B

I see I can do the opposite with a whereExists statement.

Is there such a thing as a whereDoesNotExist?

0 likes
5 replies
RushVan's avatar

@jasonfrye thanks, I didn't dig deep enough in the docs.

Any chance you have an example of how this might work?

I have tried this;

$A = Clients::where('value', '1');

$B = Clients::whereNotExists($A, 'other_table')->get();

I get this;

Argument 1 passed to Illuminate\Database\Query\Builder::whereNotExists() must be an instance of Closure, instance of Illuminate\Database\Eloquent\Builder given

pmall's avatar

@Tenzing you are putting a query builder in a function expecting a closure.

Please or to participate in this conversation.