|
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
|
14 |
|
public function register() |
|
15
|
|
|
{ |
|
16
|
14 |
|
$this->app->register(\Yajra\DataTables\DataTablesServiceProvider::class); |
|
17
|
14 |
|
$this->app->register(\Yajra\DataTables\ButtonsServiceProvider::class); |
|
18
|
|
|
|
|
19
|
14 |
|
$this->replaceBindings(); |
|
20
|
|
|
|
|
21
|
14 |
|
$this->configureDataTables(); |
|
22
|
14 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Replace the original DataTables bindings. |
|
26
|
|
|
* |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
14 |
|
protected function replaceBindings() |
|
30
|
|
|
{ |
|
31
|
14 |
|
$this->app->alias('datatables', DataTables::class); |
|
32
|
14 |
|
$this->app->singleton('datatables', function () { |
|
33
|
8 |
|
return new DataTables; |
|
34
|
14 |
|
}); |
|
35
|
|
|
|
|
36
|
14 |
|
$this->app->bind('datatables.html', Html\Builder::class); |
|
37
|
14 |
|
} |
|
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
|
14 |
|
protected function configureDataTables() |
|
48
|
|
|
{ |
|
49
|
14 |
|
$this->mergeConfig('datatables.builders', [ |
|
50
|
14 |
|
\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
|
14 |
|
$this->mergeConfig('datatables-buttons', [ |
|
57
|
14 |
|
'stub' => '/vendor/elfsundae/laravel-datatables/src/stubs', |
|
58
|
|
|
]); |
|
59
|
14 |
|
} |
|
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
|
14 |
|
protected function mergeConfig($key, array $config) |
|
69
|
|
|
{ |
|
70
|
14 |
|
$current = $this->app['config']->get($key, []); |
|
71
|
|
|
|
|
72
|
14 |
|
$this->app['config']->set($key, array_merge($config, $current)); |
|
73
|
14 |
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|