12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Models;
- // use Illuminate\Contracts\Auth\MustVerifyEmail;
- use App\Models\Scopes\CompanyScope;
- 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);
- }
- }
|