In this blog we will discuss how to convert laravel collection to simple php array.
Laravel collection to array
Laravel use toArray() function on collection for changing simple array.
public function index() { $arr = [1,3,5,7,9]; $collection = collect($arr); //change array to collection dd($collection->toArray()); //change again collection to array. }
Laravel collection to json
Laravel use toJson() function on collection for changing json type data.
public function index() { $arr = [1,3,5,7,9]; $collection = collect($arr); //change array to collection dd($collection->toJson()); //change collection to json object. }
Read Also : Laravel nested relationship with eager loading