質問

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?

役に立ちましたか?

解決

This is how you do it:

$builder = Post::query();

他のヒント

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

   $builder = Post::query()->whereNull('id')
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top