Skip to content

Commit

Permalink
Merge pull request #23 from pktharindu/patch-1
Browse files Browse the repository at this point in the history
Ability to pass array, Closure or Collection to options
  • Loading branch information
tanthammar authored Oct 5, 2020
2 parents eb571fa + ecab094 commit 0881024
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Traits/HasOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ trait HasOptions
public $callableOptions;

/**
* Flat key => value based Array.
* Flat key => value based Array, Collection or Closure.
* You can use a component method; ->options($this->someMethod())
* @param array $options
* @param array|\Closure|\Illuminate\Support\Collection $options
* @return $this
*/
public function options(array $options = []): self
public function options($options): self
{
$this->arrayFlipOrCombine($options);
if (is_callable($options)) {
$options = $options();
}

$this->arrayFlipOrCombine(collect($options ?? [])->toArray());
return $this;
}

Expand Down

0 comments on commit 0881024

Please sign in to comment.