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