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;
|
2018-07-05 07:58:26 +00:00
|
|
|
use Webkul\User\Notifications\AdminResetPassword;
|
2019-02-18 07:30:40 +00:00
|
|
|
use Webkul\User\Contracts\Admin as AdminContract;
|
2018-07-05 07:58:26 +00:00
|
|
|
|
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 = [
|
2020-01-03 08:14:12 +00:00
|
|
|
'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 = [
|
2020-01-03 08:14:12 +00:00
|
|
|
'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
|
|
|
}
|
|
|
|
|
|
2018-07-05 07:58:26 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|