mirror of
https://github.com/robonen/education-project.git
synced 2026-03-20 10:54:31 +00:00
Регистрация и вход для всех ролей
This commit is contained in:
68
app/Models/User.php
Normal file
68
app/Models/User.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user