Ejemplo 1: roles y permisos de laravel
composer require spatie/laravel-permission
Ejemplo 2: obtener usuarios por nombre de rol – Spatie / Laravel-Permiso
User::whereHas("roles", function($q){ $q->where("name", "Member"); })->get()
Ejemplo 3: tutorial de permisos y roles espaciales de laravel
cd ~/Sites
laravel new mypermissionsdemo
cd mypermissionsdemo
git init
git add .
git commit -m "Fresh Laravel Install"
# Environment
cp -n .env.example .env
sed -i '' 's/DB_CONNECTION=mysql/DB_CONNECTION=sqlite/' .env
sed -i '' 's/DB_DATABASE=/#DB_DATABASE=/' .env
touch database/database.sqlite
# Package
composer require spatie/laravel-permission
php artisan vendor:publish --provider="SpatiePermissionPermissionServiceProvider"
git add .
git commit -m "Add Spatie Laravel Permissions package"
php artisan migrate:fresh
# Add `HasRoles` trait to User model
sed -i '' $'s/use Notifiable;/use Notifiable;\n use \\Spatie\\Permission\\Traits\\HasRoles;/' app/User.php
sed -i '' $'s/use HasFactory, Notifiable;/use HasFactory, Notifiable;\n use \\Spatie\\Permission\\Traits\\HasRoles;/' app/Models/User.php
git add . && git commit -m "Add HasRoles trait"
# Add Laravel's basic auth scaffolding
composer require laravel/ui --dev
php artisan ui bootstrap --auth
# npm install && npm run prod
git add . && git commit -m "Setup auth scaffold"
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)