79 lines
1.6 KiB
PHP
79 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Permission\Models\Role;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, HasFactory, Notifiable, HasRoles;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
|
|
public static function getAllUsers()
|
|
{
|
|
return self::all();
|
|
}
|
|
|
|
public static function assignRoleToUser($userid,$rolename)
|
|
{
|
|
$user = self::find($userid);
|
|
$role= $user->assignRole($rolename);
|
|
}
|
|
|
|
public static function assignPermissionToUser($userid,$permissionname)
|
|
{
|
|
$user = self::find($userid);
|
|
$permission= $user->givePermissionTo($permissionname);
|
|
}
|
|
|
|
public static function getAllPermissions()
|
|
{
|
|
return Permission::all();
|
|
}
|
|
|
|
public static function getAllRoles()
|
|
{
|
|
return Role::all();
|
|
}
|
|
|
|
|
|
}
|
|
|