Conditions | 4 |
Paths | 1 |
Total Lines | 28 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | public function boot() |
||
17 | { |
||
18 | form()->macro('categories', function ($name = 'category_id', $selected = null, $options = []) { |
||
19 | $html = []; |
||
20 | Category::lists()->each(function (Category $category) use (&$html, $selected, $name) { |
||
21 | $selected = form()->getValueAttribute($name, $selected); |
||
|
|||
22 | |||
23 | if (is_array($selected)) { |
||
24 | $selected = in_array($category->id, $selected) ? 'selected' : null; |
||
25 | } else { |
||
26 | $selected = ((string)$category->id == (string)$selected) ? 'selected' : null; |
||
27 | } |
||
28 | |||
29 | $options = [ |
||
30 | 'value' => $category->id, |
||
31 | 'selected' => $selected, |
||
32 | 'data-alias' => $category->present()->alias, |
||
33 | ]; |
||
34 | |||
35 | $html[] = new HtmlString('<option ' . html()->attributes($options) . '>' . e($category->present()->indentedTitle) . '</option>'); |
||
36 | }); |
||
37 | |||
38 | $list = implode('', $html); |
||
39 | $options = html()->attributes($options + ['name' => $name]); |
||
40 | |||
41 | return new HtmlString("<select{$options}>{$list}</select>"); |
||
42 | }); |
||
43 | } |
||
44 | |||
55 |
It seems like you are assigning to a variable which was imported through a
use
statement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope