123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Models;
- // use Illuminate\Contracts\Auth\MustVerifyEmail;
- use Illuminate\Database\Eloquent\Casts\Attribute;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- use Laravel\Sanctum\HasApiTokens;
- use Spatie\Permission\Traits\HasRoles;
- class User extends Authenticatable
- {
- use HasApiTokens, HasFactory, Notifiable, HasRoles;
- protected string $guard_name = 'api';
- /**
- * The attributes that are mass assignable.
- *
- * @var array<int, string>
- */
- protected $fillable = [
- 'name',
- 'username',
- 'email',
- 'password',
- 'company_id',
- 'department_id',
- ];
- /**
- * The attributes that should be hidden for serialization.
- *
- * @var array<int, string>
- */
- protected $hidden = [
- 'password',
- 'remember_token',
- ];
- /**
- * The attributes that should be cast.
- *
- * @var array<string, string>
- */
- protected $casts = [
- 'email_verified_at' => 'datetime',
- 'password' => 'hashed',
- ];
- protected function superAdmin(): Attribute
- {
- return Attribute::make(
- get: fn() => $this->role_id == config("auth.super_admin_role_id"),
- );
- }
- public function guardName(): string
- {
- return $this->guard_name;
- }
- public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo
- {
- return $this->belongsTo(Company::class);
- }
- public function role(): \Illuminate\Database\Eloquent\Relations\BelongsTo
- {
- return $this->belongsTo(Role::class);
- }
- public function createdBy(): \Illuminate\Database\Eloquent\Relations\BelongsTo
- {
- return $this->belongsTo(User::class, 'created_by');
- }
- public function department(): \Illuminate\Database\Eloquent\Relations\BelongsTo
- {
- return $this->belongsTo(Department::class);
- }
- }
|