Skip to content

Commit 6cd3527

Browse files
committed
Fixes issue with populating select from Model in Laravel 5.1.
Signed-off-by: crynobone <crynobone@gmail.com>
1 parent cea6952 commit 6cd3527

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Traits/SelectionTrait.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php namespace Collective\Html\Traits;
22

3+
use Illuminate\Contracts\Support\Arrayable;
4+
35
trait SelectionTrait
46
{
57
/**
@@ -125,12 +127,16 @@ protected function placeholderOption($display, $selected)
125127
* Determine if the value is selected.
126128
*
127129
* @param string $value
128-
* @param string $selected
130+
* @param string|array|\Illuminate\Contracts\Support\Arrayable $selected
129131
*
130132
* @return string
131133
*/
132134
protected function getSelectedValue($value, $selected)
133135
{
136+
if ($selected instanceof Arrayable) {
137+
$selected = $selected->toArray();
138+
}
139+
134140
if (is_array($selected)) {
135141
return in_array($value, $selected) ? 'selected' : null;
136142
}

0 commit comments

Comments
 (0)