Skip to content

Commit 631dcb1

Browse files
committed
check if there is a connection with the db before registering the permissions
1 parent 5f0b536 commit 631dcb1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/PermissionServiceProvider.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Maklad\Permission\Contracts\PermissionInterface as Permission;
99
use Maklad\Permission\Contracts\RoleInterface as Role;
1010
use Maklad\Permission\Directives\PermissionDirectives;
11+
use Illuminate\Support\Facades\DB;
1112

1213
/**
1314
* Class PermissionServiceProvider
@@ -41,9 +42,12 @@ public function boot()
4142

4243
$this->registerModelBindings();
4344

44-
$this->app->afterResolving(Gate::class, function () {
45+
try {
46+
DB::connection()->getPdo();
4547
app(PermissionRegistrar::class)->registerPermissions();
46-
});
48+
} catch (\Exception $e) {
49+
die("Could not connect to the database. Please check your configuration. error:" . $e);
50+
}
4751
}
4852

4953
public function register()

0 commit comments

Comments
 (0)