5
5
use App \Models \Userlog ;
6
6
use Illuminate \Database \Eloquent \Model ;
7
7
use Illuminate \Database \QueryException ;
8
+ use Illuminate \Foundation \Console \AboutCommand ;
8
9
use Illuminate \Pagination \Paginator ;
9
10
use Illuminate \Support \Facades \DB ;
10
11
use Illuminate \Support \Facades \Event ;
11
12
use Illuminate \Support \Facades \Gate ;
12
13
use Illuminate \Support \Facades \Log ;
13
14
use Illuminate \Support \ServiceProvider ;
14
15
use Illuminate \Support \Str ;
16
+ use Opcodes \LogViewer \Facades \LogViewer ;
15
17
use Stevebauman \Location \Facades \Location ;
16
18
17
19
class AppServiceProvider extends ServiceProvider
@@ -29,31 +31,60 @@ public function register(): void
29
31
*/
30
32
public function boot (): void
31
33
{
34
+ // -----------------------------------------------------------------------
35
+ // Pagination
36
+ // -----------------------------------------------------------------------
32
37
Paginator::useBootstrapFive ();
33
38
39
+ // -----------------------------------------------------------------------
34
40
// log all queries when in not in production
41
+ // -----------------------------------------------------------------------
35
42
if (! app ()->isProduction ()) {
36
43
DB ::listen (function ($ query ) {
37
44
logger (Str::replaceArray ('? ' , $ query ->bindings , $ query ->sql ));
38
45
});
39
46
}
40
-
47
+ // -----------------------------------------------------------------------
41
48
// log all N+1 queries
49
+ // -----------------------------------------------------------------------
42
50
Model::preventLazyLoading ();
43
51
44
52
Model::handleLazyLoadingViolationUsing (function ($ model , $ relation ) {
45
53
Log::warning ("N+1 Query detected. \r\n" . sprintf ('N+1 Query detected in model %s on relation %s. ' , get_class ($ model ), $ relation ));
46
54
});
47
55
56
+ // -----------------------------------------------------------------------
57
+ // Developer only
58
+ // -----------------------------------------------------------------------
48
59
Gate::define ('developer ' , function ($ user ) {
49
60
return $ user ->is_developer ;
50
61
});
51
62
63
+ // -----------------------------------------------------------------------
64
+ // Log Viewer : grant access (in production) to developer
65
+ // -----------------------------------------------------------------------
66
+ LogViewer::auth (function ($ request ) {
67
+ return auth ()->user () && auth ()->user ()->is_developer ;
68
+ });
69
+
70
+ // -----------------------------------------------------------------------
71
+ // Init application
72
+ // -----------------------------------------------------------------------
52
73
Event::listen (\Illuminate \Auth \Events \Login::class, function ($ event ) {
53
74
$ this ->setYear ();
54
75
55
76
$ this ->logUser ($ event ->user );
56
77
});
78
+
79
+ // -----------------------------------------------------------------------
80
+ // about
81
+ // -----------------------------------------------------------------------
82
+ AboutCommand::add ('Application ' , [
83
+ 'Name ' => 'L11 - BS 5 - DT 2 ' ,
84
+ 'author ' => 'kreaweb.be ' ,
85
+ 'github ' => 'https://github.com/MGeurts/laravel-11-bootstrap-5-datatables ' ,
86
+ 'license ' => 'MIT License ' ,
87
+ ]);
57
88
}
58
89
59
90
private function setYear ()
0 commit comments