70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasApiTokens, HasFactory, Notifiable, SoftDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $user) {
|
|
if (empty($user->ulid)) {
|
|
$user->ulid = \Illuminate\Support\Str::ulid();
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 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 [
|
|
'email_verified_at' => 'datetime',
|
|
'two_factor_confirmed_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
}
|
|
|
|
public function workspaces(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Domains\Workspace\Models\Workspace::class, 'owner_id');
|
|
}
|
|
|
|
public function defaultWorkspace(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Domains\Workspace\Models\Workspace::class, 'default_workspace_id');
|
|
}
|
|
|
|
public function workspaceMemberships(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Domains\Workspace\Models\WorkspaceMember::class);
|
|
}
|
|
}
|