Forget doesn't work
You did a small mistake, actually you didn't notice that. I did myself :).
Forget
use the array key
to delete an object item from collection.
Array(0 => 'abc'
1 => 'bcd'
49 => 'aaa'
)
$examples->forget(49);
^^ array key 49
Where as, find
use the id
to find an object from an collection
table: examples
id example
1 abc
49 bce
$examples->find(49);
^^ `example id`
I just wanted to add on to the Anam's answer. Once you have a collection you can then loop through it like this to delete by ID
function forgetById($collection,$id){
foreach($collection as $key => $item){
if($item->id == $id){
$collection->forget($key);
break;
}
}
return $collection;
}
$examples = Example::where('example', '=', $data['example'])->get();
$examples = forgetById($examples,20);