|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ProtoneMedia\LaravelFormComponents\Support; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
use Illuminate\Support\Facades\Blade; |
|
7
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
|
8
|
|
|
use ProtoneMedia\LaravelFormComponents\FormDataBinder; |
|
9
|
|
|
|
|
10
|
|
|
class ServiceProvider extends BaseServiceProvider |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Bootstrap the application services. |
|
14
|
|
|
*/ |
|
15
|
|
|
public function boot() |
|
16
|
|
|
{ |
|
17
|
|
|
if ($this->app->runningInConsole()) { |
|
18
|
|
|
$this->publishes([ |
|
19
|
|
|
__DIR__ . '/../../config/config.php' => config_path('form-components.php'), |
|
20
|
|
|
], 'config'); |
|
21
|
|
|
|
|
22
|
|
|
$this->publishes([ |
|
23
|
|
|
__DIR__ . '/../../resources/views' => base_path('resources/views/vendor/form-components'), |
|
24
|
|
|
], 'views'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'form-components'); |
|
28
|
|
|
|
|
29
|
|
|
// |
|
30
|
|
|
|
|
31
|
|
|
Blade::directive('bind', function ($bind) { |
|
32
|
|
|
return '<?php app(\ProtoneMedia\LaravelFormComponents\FormDataBinder::class)->bind(' . $bind . '); ?>'; |
|
33
|
|
|
}); |
|
34
|
|
|
|
|
35
|
|
|
Blade::directive('endbind', function () { |
|
36
|
|
|
return '<?php app(\ProtoneMedia\LaravelFormComponents\FormDataBinder::class)->pop(); ?>'; |
|
37
|
|
|
}); |
|
38
|
|
|
|
|
39
|
|
|
Blade::directive('wire', function ($modifier) { |
|
40
|
|
|
return '<?php app(\ProtoneMedia\LaravelFormComponents\FormDataBinder::class)->wire(' . $modifier . '); ?>'; |
|
41
|
|
|
}); |
|
42
|
|
|
|
|
43
|
|
|
Blade::directive('endwire', function () { |
|
44
|
|
|
return '<?php app(\ProtoneMedia\LaravelFormComponents\FormDataBinder::class)->endWire(); ?>'; |
|
45
|
|
|
}); |
|
46
|
|
|
|
|
47
|
|
|
// |
|
48
|
|
|
|
|
49
|
|
|
$prefix = config('form-components.prefix'); |
|
50
|
|
|
|
|
51
|
|
|
Collection::make(config('form-components.components'))->each( |
|
52
|
|
|
fn ($component, $alias) => Blade::component($alias, $component['class'], $prefix) |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Register the application services. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function register() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'form-components'); |
|
62
|
|
|
|
|
63
|
|
|
$this->app->singleton(FormDataBinder::class, fn () => new FormDataBinder); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|