문제

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