I was wondering if you could remove or forget an item by key when using each() method in Laravel.
I have tried this:
$Items = Items::all();
$Items->each(function($Item, $Key){
if($Item->removable){
$this->forget($Key);
}
});
And I have also tried this:
$Items = Items:all();
$Items->each(function($Item, $Key) use (&$Items){
if($Item->removable){
$Items->forget($Key);
}
});
And it seems to just be removing all items instead of the ones that would have my true conditional values (in this e.g. $Item->removable).
Can anyone shine some light on this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire