Harris Khan
Harris Khan

Reputation: 265

filter on collection giving different resuts

I have Laravel collection when I dump collection and when I filter collection and then dump it shows me different results. Can anybody tell me what is the difference between these two ?? The screenshot is attached below

enter image description here

enter image description here

I am filtering collection like this :

$non_uploaded_orders = $batch_orders->filter(function($item){
            return ($item->batch_id == null && $item->status != 'declined');
        });

Upvotes: 0

Views: 50

Answers (1)

fahim152
fahim152

Reputation: 2629

When you use dump(), it basically shows you the whole collection. Same collection when you use dd(). However dd() shows the whole collection and stops execution of the code. dump() will show you the collection, but won't stop the execution of the code.

When you use filter(), filter will give you the filtered collection data which you give in the call back. If no callback is supplied, all entries of the collection that are equivalent to false will be removed.

Upvotes: 1

Related Questions