1. Go to this page and download the library: Download afurgeri/laravel-rbac library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
afurgeri / laravel-rbac example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Rbac\Concerns\HasRoles;
use Modules\Rbac\Contracts\HasPermissions;
use MongoDB\Laravel\Auth\User as Authenticatable;
class User extends Authenticatable implements HasPermissions
{
use HasFactory, HasRoles;
protected $connection = 'mongodb';
protected $table = 'users';
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected function casts(): array
{
return [
'password' => 'hashed',
'email_verified_at' => 'datetime',
];
}
}
use Illuminate\Foundation\Auth\User as Authenticatable;
use Modules\Rbac\Concerns\HasRoles;
use Modules\Rbac\Contracts\HasPermissions;
class User extends Authenticatable implements HasPermissions
{
use HasRoles;
}
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Schema::connection('mongodb')->table('users', static function (Blueprint $blueprint): void {
$blueprint->unique('email');
$blueprint->index('role_ids');
});