Flamms Flamms - 3 years ago 126
JSON Question

Shuffle Array from Collection

I want to shuffel an array. But it will not work. This is my Query in Laravel

$spielerArray = Spieler::join('PlanungSpieler', 'PlanungSpieler.Player_ID', '=', 'Spieler.Player_ID')
->select('Spieler.Player_ID')->get();


And in the next step I want only shuffle the column Spieler.Player.

$finalShuffleResult = shuffle($spielerArray->Player_ID)


I get
Player_ID Instance does not exist on this collection

Here is a part of my collection

Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => App\Spieler Object
(
[table:protected] => Spieler
[connection:protected] => mysql
[primaryKey:protected] => id
[keyType:protected] => int
[incrementing] => 1
[with:protected] => Array
(
)

[withCount:protected] => Array
(
)

[perPage:protected] => 15
[exists] => 1
[wasRecentlyCreated] =>
[attributes:protected] => Array
(
[Player_ID] => 101
)


How can I get Player_ID with the goal to shuffle them?

Answer Source

use this $finalShuffleResult = $spielerArray->pluck('Player_ID')->shuffle()->all();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download