Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get an empty Builder for a model?

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?

like image 694
barakuda28 Avatar asked Jan 03 '14 22:01

barakuda28


1 Answers

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

   $builder = Post::query()->whereNull('id')
like image 192
Lam Kwok Shing Avatar answered Nov 21 '22 03:11

Lam Kwok Shing