1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Socialblue\LaravelQueryAdviser; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
6
|
|
|
use Illuminate\Support\Facades\Route; |
7
|
|
|
use Illuminate\Support\Facades\DB; |
8
|
|
|
use Illuminate\Support\ServiceProvider; |
9
|
|
|
use Socialblue\LaravelQueryAdviser\DataListener\QueryListener; |
10
|
|
|
use Socialblue\LaravelQueryAdviser\Helper\QueryBuilderHelper; |
11
|
|
|
|
12
|
|
|
class LaravelQueryAdviserServiceProvider extends ServiceProvider |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Bootstrap the application services. |
16
|
|
|
*/ |
17
|
|
|
public function boot() |
18
|
|
|
{ |
19
|
|
|
/* |
20
|
|
|
* Optional methods to load your package assets |
21
|
|
|
*/ |
22
|
|
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'QueryAdviser'); |
23
|
|
|
|
24
|
|
|
Route::group([ |
25
|
|
|
'prefix' => 'query-adviser', |
26
|
|
|
'namespace' => 'Socialblue\LaravelQueryAdviser\Http\Controllers', |
27
|
|
|
'middleware' =>'web', |
28
|
|
|
], function () { |
29
|
|
|
$this->loadRoutesFrom(__DIR__.'/../routes/web.php'); |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
$this->publishes([ |
33
|
|
|
__DIR__.'/../public' => public_path('vendor/socialblue/laravel-query-adviser'), |
34
|
|
|
], 'public'); |
35
|
|
|
|
36
|
|
|
$this->publishes([ |
37
|
|
|
__DIR__.'/../config/config.php' => config_path('laravel-query-adviser.php'), |
38
|
|
|
], 'config'); |
39
|
|
|
|
40
|
|
|
$this->bootLaravelQueryAdviser(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Register the application services. |
45
|
|
|
*/ |
46
|
|
|
public function register() |
47
|
|
|
{ |
48
|
|
|
// Automatically apply the package configuration |
49
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-query-adviser'); |
50
|
|
|
|
51
|
|
|
// Register the main class to use with the facade |
52
|
|
|
$this->app->singleton('laravel-query-adviser', function () { |
53
|
|
|
return new LaravelQueryAdviser; |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Add helper functions to app |
59
|
|
|
*/ |
60
|
|
|
protected function bootLaravelQueryAdviser() |
61
|
|
|
{ |
62
|
|
|
DB::listen(static function ($query) { |
63
|
|
|
QueryListener::listen($query); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
Builder::macro('dd', function () { |
67
|
|
|
dd(QueryBuilderHelper::infoByBuilder($this)); |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
Builder::macro('dump', function () { |
71
|
|
|
dump(QueryBuilderHelper::infoByBuilder($this)); |
72
|
|
|
}); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|