Primo commit
This commit is contained in:
78
app/Models/User.php
Normal file
78
app/Models/User.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user