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?

Was it helpful?

Solution

This is how you do it:

$builder = Post::query();

OTHER TIPS

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

   $builder = Post::query()->whereNull('id')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top