story ks
story ks

Reputation: 850

Laravel get all value from collection or array

i need ur help

This is information from the form.

enter image description here

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());

This my debug enter image description here

Thing I want

facility = [40,39,42,43,44,41,38,2]

Upvotes: 1

Views: 8005

Answers (1)

Patrick Schocke
Patrick Schocke

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

Related Questions