| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Models;
- // use Illuminate\Contracts\Auth\MustVerifyEmail;
- use App\Enums\UserLanguageSource;
- use App\Enums\UserTypeSource;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- use Laravel\Sanctum\HasApiTokens;
- use Illuminate\Database\Eloquent\Relations\BelongsToMany;
- class User extends Authenticatable
- {
- use HasFactory, Notifiable, HasApiTokens;
- /**
- * The attributes that are mass assignable.
- *
- * @var array<int, string>
- */
- protected $fillable = [
- 'name',
- 'email',
- 'password',
- ];
- /**
- * The attributes that should be hidden for serialization.
- *
- * @var array<int, string>
- */
- protected $hidden = [
- 'password',
- 'remember_token',
- ];
- /**
- * Get the attributes that should be cast.
- *
- * @return array<string, string>
- */
- protected function casts(): array
- {
- return [
- 'email_verified_at' => 'datetime',
- 'password' => 'hashed',
- 'type' => UserTypeSource::class,
- 'language' => UserLanguageSource::class,
- ];
- }
- public function isAdmin(): bool
- {
- return $this->type === UserTypeSource::Admin;
- }
- public function isRegularUser(): bool
- {
- return $this->type === UserTypeSource::RegularUser;
- }
- public function isPayingUser(): bool
- {
- return $this->type === UserTypeSource::PayingUser;
- }
- public function isGuest(): bool
- {
- return $this->type === UserTypeSource::Guest;
- }
- public function permissions(): BelongsToMany
- {
- return $this->belongsToMany(Permission::class, 'user_type_permissions', 'user_type', 'permission_id');
- }
- }
|