Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/AAuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AuroraWebSoftware\AAuth\Commands\AAuthCommand;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Session;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand Down Expand Up @@ -52,6 +53,10 @@ public function boot(): void
);
});

Gate::before(function ($user, $ability, $arguments = []) {
return app('aauth')->can($ability) ?: null;
});

Blade::directive('aauth', function ($permission) {
return "<?php if(\AuroraWebSoftware\AAuth\Facades\AAuth::can($permission)){ ?>";
});
Expand Down
19 changes: 19 additions & 0 deletions src/Traits/AAuthUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@ public function getDeletableAttribute(): bool
// todo new syntax
return $this->getAssignedUserCountAttribute() == 0;
}

public function can($abilities, $arguments = []): bool
{
if (is_string($abilities)) {
return app('aauth')->can($abilities);
}

if (is_array($abilities)) {
foreach ($abilities as $ability) {
if (! app('aauth')->can($ability)) {
return false;
}
}

return true;
}

return parent::can($abilities, $arguments);
}
}