Reputation: 850
i need ur help
This is information from the form.
I will rearrange the structure according to the document. https://laravel.com/docs/5.4/collections#method-collapse
This my code
$facility = collect($request->facility);
$item = $facility->collapse();
dd($item->all());
Thing I want
facility = [40,39,42,43,44,41,38,2]
Upvotes: 1
Views: 8005
Reputation: 1491
You don't need to take any action on this. $request->facility
will return the array you want. The reason, why the array looks different in your console, is the browser.
[2,3,4,5]
is equal to
[
0 => 2,
1 => 3,
2 => 4,
3 => 5
]
This simply shows the position of the value in the array. Read more here
The collapse()
method will combine multiple arrays into one:
$collection = collect([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
$collapsed = $collection->collapse();
$collapsed->all();
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
Upvotes: 3