1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElfSundae\DataTables; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
|
7
|
|
|
class DataTablesServiceProvider extends ServiceProvider |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Register the service provider. |
11
|
|
|
* |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
7 |
|
public function register() |
15
|
|
|
{ |
16
|
7 |
|
$this->app->register(\Yajra\DataTables\DataTablesServiceProvider::class); |
17
|
7 |
|
$this->app->register(\Yajra\DataTables\ButtonsServiceProvider::class); |
18
|
|
|
|
19
|
7 |
|
$this->replaceBindings(); |
20
|
|
|
|
21
|
7 |
|
$this->configureDataTables(); |
22
|
7 |
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Replace the original DataTables bindings. |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
7 |
|
protected function replaceBindings() |
30
|
|
|
{ |
31
|
7 |
|
$this->app->alias('datatables', DataTables::class); |
32
|
7 |
|
$this->app->singleton('datatables', function () { |
33
|
4 |
|
return new DataTables; |
34
|
7 |
|
}); |
35
|
|
|
|
36
|
7 |
|
$this->app->bind('datatables.html', Html\Builder::class); |
37
|
7 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Configure DataTables. |
41
|
|
|
* |
42
|
|
|
* - Restore the default "builders" configuration, see https://github.com/yajra/laravel-datatables/pull/1462/commits/afdbe6bce9ade9b19d66034ace3d8a2c24da8a56 |
43
|
|
|
* - Configure our custom DataTable service stub for "datatables:make" command |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
7 |
|
protected function configureDataTables() |
48
|
|
|
{ |
49
|
7 |
|
$this->mergeConfig('datatables.builders', [ |
50
|
7 |
|
\Illuminate\Database\Eloquent\Builder::class => 'eloquent', |
51
|
|
|
\Illuminate\Database\Eloquent\Relations\Relation::class => 'eloquent', |
52
|
|
|
\Illuminate\Database\Query\Builder::class => 'query', |
53
|
|
|
\Illuminate\Support\Collection::class => 'collection', |
54
|
|
|
]); |
55
|
|
|
|
56
|
7 |
|
$this->mergeConfig('datatables-buttons', [ |
57
|
7 |
|
'stub' => '/vendor/elfsundae/laravel-datatables/src/stubs', |
58
|
|
|
]); |
59
|
7 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Merge the given configuration with the existing configuration. |
63
|
|
|
* |
64
|
|
|
* @param string $key |
65
|
|
|
* @param array $config |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
7 |
|
protected function mergeConfig($key, array $config) |
69
|
|
|
{ |
70
|
7 |
|
$current = $this->app['config']->get($key, []); |
71
|
|
|
|
72
|
7 |
|
$this->app['config']->set($key, array_merge($config, $current)); |
73
|
7 |
|
} |
74
|
|
|
} |
75
|
|
|
|