Skip to content

Commit 4ff9346

Browse files
authored
Merge pull request #88 from AuroraWebSoftware/general-updates
General updates
2 parents c7bd918 + 5af91db commit 4ff9346

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/AAuthServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use AuroraWebSoftware\AAuth\Commands\AAuthCommand;
66
use Illuminate\Support\Facades\Auth;
77
use Illuminate\Support\Facades\Blade;
8+
use Illuminate\Support\Facades\Gate;
89
use Illuminate\Support\Facades\Session;
910
use Spatie\LaravelPackageTools\Package;
1011
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -52,6 +53,10 @@ public function boot(): void
5253
);
5354
});
5455

56+
Gate::before(function ($user, $ability, $arguments = []) {
57+
return app('aauth')->can($ability) ?: null;
58+
});
59+
5560
Blade::directive('aauth', function ($permission) {
5661
return "<?php if(\AuroraWebSoftware\AAuth\Facades\AAuth::can($permission)){ ?>";
5762
});

src/Traits/AAuthUser.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,23 @@ public function getDeletableAttribute(): bool
7171
// todo new syntax
7272
return $this->getAssignedUserCountAttribute() == 0;
7373
}
74+
75+
public function can($abilities, $arguments = []): bool
76+
{
77+
if (is_string($abilities)) {
78+
return app('aauth')->can($abilities);
79+
}
80+
81+
if (is_array($abilities)) {
82+
foreach ($abilities as $ability) {
83+
if (! app('aauth')->can($ability)) {
84+
return false;
85+
}
86+
}
87+
88+
return true;
89+
}
90+
91+
return parent::can($abilities, $arguments);
92+
}
7493
}

0 commit comments

Comments
 (0)