public function registerGatePolicies(): void
    {
        if (!\Schema::hasTable('permissions')) {
            return;
        }

        $permissions = Permission::all(['handle', 'type']);

        foreach ($permissions as $permission) {
            Gate::define($permission->code, function (Authenticatable $user, ?Model $model = null, string $userForeignKey = 'user_id') use ($permission) {
                return $user->hasPermission($permission->code, $model, $userForeignKey);
            });
        }
    }