-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathLaravelCustomFieldsServiceProvider.php
45 lines (36 loc) · 1.43 KB
/
LaravelCustomFieldsServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Givebutter\LaravelCustomFields;
use Givebutter\LaravelCustomFields\FieldTypes\FieldType;
use Givebutter\LaravelCustomFields\ResponseTypes\ResponseType;
use Illuminate\Support\ServiceProvider;
class LaravelCustomFieldsServiceProvider extends ServiceProvider
{
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/custom-fields.php', 'custom-fields');
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__ . '/../config/custom-fields.php' => config_path('custom-fields.php'),
], 'custom-fields-config');
if (!class_exists('CreateCustomFieldsTables')) {
$this->publishes([
__DIR__ . '/../database/migrations/create_custom_fields_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_custom_fields_tables.php'),
], 'migrations');
}
$this->app->bind(FieldType::class, function ($app, $params) {
$fieldTypeClass = config('custom-fields.fields.' . $params['type']);
return new $fieldTypeClass($params['field']);
});
$this->app->bind(ResponseType::class, function ($app, $params) {
$responseTypeClass = config('custom-fields.responses.' . $params['type']);
return new $responseTypeClass($params['response']);
});
}
}