|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\HtmlString; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use Yajra\CMS\Entities\Category; |
|
8
|
|
|
|
|
9
|
|
|
class FormServiceProvider extends ServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Bootstrap the application services. |
|
13
|
|
|
* |
|
14
|
|
|
* @return void |
|
15
|
|
|
*/ |
|
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 = ['value' => $category->id, 'selected' => $selected, 'data-alias' => $category->present()->alias]; |
|
30
|
|
|
|
|
31
|
|
|
$html[] = new HtmlString('<option ' . html()->attributes($options) . '>' . e($category->present()->indentedTitle) . '</option>'); |
|
32
|
|
|
}); |
|
33
|
|
|
|
|
34
|
|
|
$list = implode('', $html); |
|
35
|
|
|
$options = html()->attributes($options + ['name' => $name]); |
|
36
|
|
|
|
|
37
|
|
|
return new HtmlString("<select{$options}>{$list}</select>"); |
|
38
|
|
|
}); |
|
39
|
|
|
|
|
40
|
|
|
form()->macro('imageBrowser', function ($name = 'intro_image', $options = []) { |
|
41
|
|
|
return view('system.macro.image-browser', [ |
|
42
|
|
|
'name' => $name, |
|
43
|
|
|
'options' => $options, |
|
44
|
|
|
]); |
|
45
|
|
|
}); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Register the application services. |
|
50
|
|
|
* |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
|
public function register() |
|
54
|
|
|
{ |
|
55
|
|
|
// |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
It seems like you are assigning to a variable which was imported through a
usestatement 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