php - Laravel Collection keys modification -


i use filter method collection class remove objects collection. after operation, objects keys eg. 1, 4, 5 left. have elements order 0, 1, 2, 3 etc. after filter action.

is there elegant way without rewriting table new one?

thanks!

you can use laravel collection's values() method make the keys of collection in serialized order this:

// demonstration $collection = collect([     10 => ['fruit' => 'apple', 'price' => 200],     11 => ['fruit' => 'mango', 'price' => 500] ]);  $values = $collection->values();  $values->all();  /* result be:     [         0 => ['fruit' => 'apple', 'price' => 200],         1 => ['fruit' => 'mango', 'price' => 500],     ] */ 

hope helps!


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -