mirror of
https://github.com/robonen/education-project.git
synced 2026-03-20 02:44:31 +00:00
69 lines
1.3 KiB
PHP
69 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Carbon\Carbon;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasFactory, Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'login',
|
|
'email',
|
|
'password',
|
|
'role_id',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* @param array $roles
|
|
* @return bool
|
|
*/
|
|
public function hasRole(array $roles)
|
|
{
|
|
foreach ($roles as $role)
|
|
{
|
|
if ($this->role->contains('name', $role))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function role()
|
|
{
|
|
return $this->belongsTo(Role::class);
|
|
}
|
|
|
|
public function headteacher()
|
|
{
|
|
return $this->hasOne(HeadTeacher::class);
|
|
}
|
|
|
|
public function makeToken(bool $remember)
|
|
{
|
|
$token = $this->createToken(config('app.name'));
|
|
$token->token->expires_at = $remember ? Carbon::now()->addMonth() : Carbon::now()->addDay();
|
|
$token->token->save();
|
|
return $token;
|
|
}
|
|
}
|