tethys/app/User.php

89 lines
2.2 KiB
PHP
Raw Normal View History

2018-08-06 12:30:51 +00:00
<?php
namespace App;
2015-07-19 06:49:24 +00:00
use Illuminate\Database\Eloquent\Model;
2018-08-06 12:30:51 +00:00
use Illuminate\Auth\Authenticatable;
2015-07-19 06:49:24 +00:00
use Illuminate\Auth\Passwords\CanResetPassword;
2018-08-06 12:30:51 +00:00
use Illuminate\Foundation\Auth\Access\Authorizable;
2015-07-19 06:49:24 +00:00
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
2018-08-06 12:30:51 +00:00
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
#use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Support\Facades\Hash;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract, AuthorizableContract
{
use Authenticatable, CanResetPassword, Authorizable;
use HasRoles;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'accounts';
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['login', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
public function setPasswordAttribute($password)
2015-07-19 06:49:24 +00:00
{
2018-08-06 12:30:51 +00:00
if ($password) {
$this->attributes['password'] = app('hash')->needsRehash($password) ? Hash::make($password) : $password;
}
2015-07-19 06:49:24 +00:00
}
2018-08-06 12:30:51 +00:00
//public function roles()
//{
// return $this->belongsToMany(\App\Role::class, 'link_accounts_roles', 'account_id', 'role_id');
//}
2015-07-19 06:49:24 +00:00
2018-08-06 12:30:51 +00:00
public function is($roleName)
2015-07-19 06:49:24 +00:00
{
2018-08-06 12:30:51 +00:00
foreach ($this->roles()->get() as $role) {
if ($role->name == $roleName) {
2015-07-19 06:49:24 +00:00
return true;
}
}
2018-08-06 12:30:51 +00:00
return false;
2015-07-19 06:49:24 +00:00
}
2018-08-06 12:30:51 +00:00
// public function assignRole($role)
// {
// return $this->roles()->attach($role);
// }
// public function revokeRole($role)
// {
// return $this->roles()->detach($role);
// }
// public function hasRole($name)
// {
// foreach ($this->roles as $role)
// {
// if ($role->name === $name)
// {
// return true;
// }
// return false;
// }
// return false;
// }
2015-07-19 06:49:24 +00:00
}