Do note that you can't eager load a relationship with "Laravel cursor" but instead you will have to use the "lazy" method.
Laravel Query Cursor Example
use App\Models\Posts; foreach (Posts::where('published', true)->cursor() as $post) { // do whatever you want with the $post }
By default "cursor" returns Laravel LazyCollection and like normal Laravel Collection, you can use pretty much any of the available methods available.
use App\Models\Post; $users = Post::cursor() ->filter(function ($post) { return $post->id > 100; })->each(function ($post) { echo $post->id; });
Leave a reply