tethys/app/Models/User.php

108 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2018-08-06 12:30:51 +00:00
<?php
2018-09-10 13:09:10 +00:00
namespace App\Models;
2015-07-19 06:49:24 +00:00
// use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2018-08-29 15:18:15 +00:00
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
2018-08-29 15:18:15 +00:00
use Zizaco\Entrust\Traits\EntrustUserTrait;
2018-08-06 12:30:51 +00:00
use Illuminate\Support\Facades\Hash;
2018-08-29 15:18:15 +00:00
use Illuminate\Support\Collection;
use App\Models\Dataset;
2018-08-06 12:30:51 +00:00
2018-08-29 15:18:15 +00:00
class User extends Authenticatable
2018-08-06 12:30:51 +00:00
{
2018-08-29 15:18:15 +00:00
// use Authenticatable, CanResetPassword, Authorizable;
use HasFactory, Notifiable;
2018-08-29 15:18:15 +00:00
// use HasRoles;
use EntrustUserTrait;
2018-08-06 12:30:51 +00:00
/**
* 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 datasets()
{
//model, foreign key on the User model is account_id, local id of user
return $this->hasMany(Dataset::class, 'account_id', 'id');
}
2018-08-06 12:30:51 +00:00
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-29 15:18:15 +00:00
public function getAvatarUrl()
{
return "https://www.gravatar.com/avatar/" . md5($this->email) . "?d=mm";
}
public function getRoleNames(): Collection
{
return $this->roles->pluck('name');
}
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
}