laravel make role for user code example
Example 1: get user with role laravel
$students = User::whereHas(
'roles', function($q){
$q->where('name', 'Teacher');
}
)->get();
Example 2: laravel role
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
}
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
$role = Role::create(['name' => 'writer']);
$permission = Permission::create(['name' => 'edit articles']);
$users = User::role('writer')->get();