sarga/packages/Webkul/User/src/Models/Admin.php

66 lines
1.5 KiB
PHP
Raw Normal View History

2018-06-20 05:06:27 +00:00
<?php
namespace Webkul\User\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Webkul\User\Models\Role;
use Webkul\User\Notifications\AdminResetPassword;
2019-02-18 07:30:40 +00:00
use Webkul\User\Contracts\Admin as AdminContract;
2018-06-20 05:06:27 +00:00
2019-02-18 07:30:40 +00:00
class Admin extends Authenticatable implements AdminContract
2018-06-20 05:06:27 +00:00
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'api_token', 'role_id', 'status',
2018-06-20 05:06:27 +00:00
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'api_token', 'remember_token',
2018-06-20 05:06:27 +00:00
];
/**
* Get the role that owns the admin.
*/
public function role()
{
2019-02-18 07:30:40 +00:00
return $this->belongsTo(RoleProxy::modelClass());
2018-06-20 05:06:27 +00:00
}
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new AdminResetPassword($token));
}
2018-06-20 05:06:27 +00:00
/**
* Checks if admin has permission to perform certain action.
*
* @param String $permission
* @return Boolean
*/
public function hasPermission($permission)
{
2019-03-01 05:30:15 +00:00
if ($this->role->permission_type == 'custom' && ! $this->role->permissions)
return false;
2018-06-20 05:06:27 +00:00
return in_array($permission, $this->role->permissions);
}
}