coursework tasks 1 to 10

This commit is contained in:
Владимир
2026-01-07 11:55:53 +00:00
parent 9f637e6be7
commit bbe639b604
13 changed files with 545 additions and 51 deletions

View File

@@ -2,43 +2,27 @@
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
class User extends Authenticatable // все пользователи системы
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
'role',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
@@ -46,4 +30,16 @@ class User extends Authenticatable
'password' => 'hashed',
];
}
// Проверяет админ или сотрудник
public function isEmployeeOrAdmin()
{
return $this->role == 'employee' || $this->role == 'admin';
}
// Для запросов - все сотрудники и админы
public static function scopeEmployeeOrAdmin($query)
{
return $query->whereIn('role', ['employee', 'admin']);
}
}