Download the PHP package nextgen-tech/laravel-abilities without Composer
On this page you can find all versions of the php package nextgen-tech/laravel-abilities. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-abilities
Laravel Abilities
Spis treści
- Instalacja
- composer
- Service Provider
- Middleware
- Kopiowanie plików
- Migracje
- Konfiguracja
- Definicja uprawnień
- Grupy uprawnień
- Pojedyncze uprawnienie
- Aliasy
- Własna funkcja
- Zasoby uprawnień
- Sprawdzanie uprawnień
Instalacja
composer
W terminalu wpisz
Service Provider
Jeśli aplikacja korzysta z Laravela w wersji 5.5 lub wyższej to możesz pominąć ten krok.
W pliku config/app.php
do listy providerów dopisz:
Middleware
W pliku app/Http/Kernel.php
do grupy web
należy dopisać:
Kopiowanie plików
Aby skopiować z paczki niezbędne pliki wykonaj następujące polecenie:
Można także opublikować część plików podając jeden z tagów: config
, translations
, models
lub migrations
:
Migracje
Uruchom migracje
Konfiguracja
Konfiguracja paczki znajduje się w pliku config/abilities.php
.
Definicja uprawnień
Domyślnie uprawnienia znajdują się w pliku routes/abilities.php
. Ścieżkę tę można zmienić w konfiguracji.
Definiować uprawnienia należy za pomocą fasady NGT\Laravel\Abilities\Facades\Ability
lub instancji klasy NGT\Laravel\Abilities\AbilityRegistrar
.
Grupy uprawnień
Grupy definiujemy za pomocą metody group
. Grupa może składać się z wyświetlanej nazwy (label
) oraz przedrostka (prefix
), ale żadna z tych opcji nie jest obowiązkowa. Grupa może także zawierać w sobie inne grupy. Dane grupy są przekazywane do podrzędnych elementów znajdujących się w anonimowej funkcji.
Pojedyncze uprawnienie
Każde uprawnienie posiada swoją uproszczoną nazwe ($slug
) oraz wyświetlaną nazwe ($label
). Dodatkowo można zdefiniować opcje ($options
).
Aliasy
Każde uprawnienie może posiadać aliasy. Najlepszym przykładem są akcje create-store
oraz edit-update
. Aby zarządzać nimi jako jednym uprawnieniem można je zdefiniować w następujący sposób:
Własna funkcja
Aby uprawnienie nie korzystało z domyślnej metody weryfikacji można przekazać do niego funkcję. Funkcja ta zostanie wykonana zamiast domyślnej.
Zasoby uprawnień
Podobnie jak w routingu, w uprawnieniach również można definiować zasoby. Podczas tworzenia zasobu należy podać przedrostek grupy ($prefix
) oraz wyświetlaną nazwę grupy ($label
).
Dodatkowo można przekazać opcje wykluczace lub dopuszczające tylko wybrane uprawnienia.
Sprawdzanie uprawnień
Kaźde uprawnienie można sprawdzać za pomocą standardowych metod klasy Gate
:
Aby kontroler automatycznie sprawdzał uprawnienia do danych akcji można zdefiniować w nim listę powiązań między akcjami a uprawnieniami
class UserController extends Controller
{
...
public $actionAbilities = [
'index' => 'admin.user.index',
'create' => 'admin.user.create',
];
...
}
All versions of laravel-abilities with dependencies
illuminate/auth Version ^5.4|^6.0|^7.0|^8.0
illuminate/routing Version ^5.4|^6.0|^7.0|^8.0
illuminate/support Version ^5.4|^6.0|^7.0|^8.0
illuminate/translation Version ^5.4|^6.0|^7.0|^8.0