85 lines
1.9 KiB
PHP
85 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Traits\FullTextSearch;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
use OwenIt\Auditing\Contracts\Auditable;
|
|
use OwenIt\Auditing\Contracts\UserResolver;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use App\Models\Traits\Documents;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class User extends Authenticatable implements Auditable, UserResolver
|
|
{
|
|
use \OwenIt\Auditing\Auditable;
|
|
use Notifiable;
|
|
use HasRoles;
|
|
use SoftDeletes;
|
|
use FullTextSearch;
|
|
use Documents;
|
|
|
|
protected $table = 'users';
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'email', 'password', 'active'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password', 'remember_token',
|
|
];
|
|
|
|
protected $searchable = [
|
|
'name',
|
|
'email'
|
|
];
|
|
|
|
public function setPasswordAttribute($password)
|
|
{
|
|
// $this->attributes['password'] = bcrypt($password);
|
|
$this->attributes['password'] = Hash::needsRehash($password) ? Hash::make($password) : $password;
|
|
}
|
|
|
|
public static function resolve()
|
|
{
|
|
return Auth::check() ? Auth::user() : null;//->getAuthIdentifier() : null;
|
|
}
|
|
|
|
public static function resolveId()
|
|
{
|
|
return Auth::check() ? Auth::user()->getAuthIdentifier() : null;
|
|
}
|
|
|
|
public function tags()
|
|
{
|
|
return $this->belongsToMany('App\Models\Tag', 'user_tag');
|
|
}
|
|
|
|
public function departments()
|
|
{
|
|
return $this->belongsToMany('App\Models\Tag', 'user_tag')->where('type', 'abteilung');
|
|
}
|
|
|
|
public function instances()
|
|
{
|
|
return $this->belongsToMany('App\Models\Tag', 'user_tag')->where('type', 'instanz');
|
|
}
|
|
|
|
public function getIsUserAttribute()
|
|
{
|
|
return true;
|
|
}
|
|
}
|