Skip to content

Commit

Permalink
Installation
Browse files Browse the repository at this point in the history
  • Loading branch information
kreaweb.be committed Apr 12, 2024
1 parent d6d6283 commit 599dba1
Show file tree
Hide file tree
Showing 9 changed files with 487 additions and 398 deletions.
33 changes: 32 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use App\Models\Userlog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\QueryException;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Opcodes\LogViewer\Facades\LogViewer;
use Stevebauman\Location\Facades\Location;

class AppServiceProvider extends ServiceProvider
Expand All @@ -29,31 +31,60 @@ public function register(): void
*/
public function boot(): void
{
// -----------------------------------------------------------------------
// Pagination
// -----------------------------------------------------------------------
Paginator::useBootstrapFive();

// -----------------------------------------------------------------------
// log all queries when in not in production
// -----------------------------------------------------------------------
if (! app()->isProduction()) {
DB::listen(function ($query) {
logger(Str::replaceArray('?', $query->bindings, $query->sql));
});
}

// -----------------------------------------------------------------------
// log all N+1 queries
// -----------------------------------------------------------------------
Model::preventLazyLoading();

Model::handleLazyLoadingViolationUsing(function ($model, $relation) {
Log::warning("N+1 Query detected.\r\n" . sprintf('N+1 Query detected in model %s on relation %s.', get_class($model), $relation));
});

// -----------------------------------------------------------------------
// Developer only
// -----------------------------------------------------------------------
Gate::define('developer', function ($user) {
return $user->is_developer;
});

// -----------------------------------------------------------------------
// Log Viewer : grant access (in production) to developer
// -----------------------------------------------------------------------
LogViewer::auth(function ($request) {
return auth()->user() && auth()->user()->is_developer;
});

// -----------------------------------------------------------------------
// Init application
// -----------------------------------------------------------------------
Event::listen(\Illuminate\Auth\Events\Login::class, function ($event) {
$this->setYear();

$this->logUser($event->user);
});

// -----------------------------------------------------------------------
// about
// -----------------------------------------------------------------------
AboutCommand::add('Application', [
'Name' => 'L11 - BS 5 - DT 2',
'author' => 'kreaweb.be',
'github' => 'https://github.com/MGeurts/laravel-11-bootstrap-5-datatables',
'license' => 'MIT License',
]);
}

private function setYear()
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"license": "MIT",
"require": {
"php": "^8.2",
"arcanedev/log-viewer": "^11.0",
"khill/lavacharts": "3.1.*",
"laravel/framework": "^11.0",
"laravel/tinker": "^2.9",
"opcodesio/log-viewer": "^3.8",
"spatie/laravel-backup": "^8.6",
"stevebauman/location": "^7.2",
"yajra/laravel-datatables-oracle": "^11.0"
Expand Down
Loading

0 comments on commit 599dba1

Please sign in to comment.