Question

Lets say I have a function that returns a builder. In case this builder cannot be returned, I want to return an empty builder - meaning, a builder which doesn't point to any data. One which if you do a get(), you will get empty collection. Any idea?

Était-ce utile?

La solution

This is how you do it:

$builder = Post::query();

Autres conseils

If your model has primary key, you can do this as a workaround:

   $builder = Post::query()->whereNull('id')
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top