I created a command in Laravel to run on a task schedule.
Here is the command logic:
public function handle()
{
$commentNotifications = CommentNotification::where('task_performed', 0)
->get();
foreach ($commentNotifications as $commentNotification) {
//blah blah
}
$commentNotifications->update(['task_performed' => 1]);
$this->comment(sprintf('Completed %d CommentNotification(s)', $commentNotifications->count()));
}
however this returned the following error:
Method Illuminate\Database\Eloquent\Collection::update does not exist.
So I tried this instead:
$commentNotifications->task_performed = 1;
$commentNotifications->save();
but this returned:
Method Illuminate\Database\Eloquent\Collection::save does not exist.
Why is this happening?
$commentNotification->update(['task_performed' => 1]);
in the loop. – BulentCommentNotification::where('task_performed', 0)->update(['task_performed' => 1]);
– Bulent