/** * Get the values of a given key. * * @param string $value * @param string|null $key * * @return static */ public function pluck($value, $key = null) { return new static(Arr::pluck($this->items, $value, $key)); }
public function testPluckWithKeys() { $array = [['name' => 'Taylor', 'role' => 'developer'], ['name' => 'Abigail', 'role' => 'developer']]; $test1 = Arr::pluck($array, 'role', 'name'); $test2 = Arr::pluck($array, null, 'name'); $this->assertEquals(['Taylor' => 'developer', 'Abigail' => 'developer'], $test1); $this->assertEquals(['Taylor' => ['name' => 'Taylor', 'role' => 'developer'], 'Abigail' => ['name' => 'Abigail', 'role' => 'developer']], $test2); }