Ajvanho's avatar
Level 14

lazyById?

I try to update articles with lazyById as written in the documentation, but have an error Method Illuminate\Database\Eloquent\Collection::lazyById does not exist

$articles->lazyById(200, $column = 'id')
    ->each->update(['departed' => false]);
0 likes
4 replies
Nakov's avatar

Can you show how do you get the $articles?

Ajvanho's avatar
Level 14

@Nakov $articles are elequent collection

Illuminate\Database\Eloquent\Collection {#2431
  #items: array:94 [
Nakov's avatar

@Ajvanho I am asking you to show the code on how you set that variable, not what is in it..

If you do:

Article::lazyById

will it work?

mterolli's avatar

@ajvanho You will have to apply the lazyById() method over a Query Builder instance not a collection, for example: Articles::where(...)->lazyById(...) It seems like you are doing something like this: $articles = Articles::where(...)->get(); $articles->lazyById(...) Hope this helps.

1 like

Please or to participate in this conversation.