Viewing file: Admin.php (2.27 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Models;
use App\Notifications\AdminResetPasswordNotification; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\DB; use Spatie\Permission\Traits\HasRoles;
class Admin extends Authenticatable { use HasFactory, HasRoles, Notifiable;
protected $guard = 'admin';
/** * The attributes that are mass assignable. * * @var array */ protected $guarded = [];
/** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ];
/** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ];
public static function getPermissionGroup() { $permission_group = DB::table('permissions') ->select('group_name as name') ->groupBy('group_name') ->get();
return $permission_group; }
public static function getpermissionsByGroupName($group_name) { $permissions = DB::table('permissions') ->select('name', 'id') ->where('group_name', $group_name) ->get();
return $permissions; }
public static function roleHasPermission($role, $permissions) { $hasPermission = true; foreach ($permissions as $permission) { if (! $role->hasPermissionTo($permission->name)) { $hasPermission = false;
return $hasPermission; } }
return $hasPermission; }
/** * Backend user image url * * @return string */ public function getImageUrlAttribute() { $image = $this->image; if ($image) { return asset($image); } else { return '/backend/image/default-user.png'; } }
/** * Send a password reset notification to the user. * * @param string $token * @return void */ public function sendPasswordResetNotification($token) { $this->notify(new AdminResetPasswordNotification($token)); } }
|