add new element in laravel collection object

It looks like you have everything correct according to Laravel docs, but you have a typo

$item->push($product);

Should be

$items->push($product);

push method appends an item to the end of the collection:

I also want to think the actual method you’re looking for is put

$items->put('products', $product);

put method sets the given key and value in the collection

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)