Stories 0.2-0.5: rename folders→declarations (backend+frontend), configure Redis for cache/queue/sessions, add foundation database migrations (permissions, archived_at), replace DeclarationStatus enum with architecture lifecycle values, create DeclarationObserver for status transition validation and auto-archive, fix controller status transitions to respect observer rules. 93 tests pass (240 assertions). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
90 lines
2.1 KiB
PHP
90 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Support\Str;
|
|
use Spatie\Activitylog\LogOptions;
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
class Workspace extends Model
|
|
{
|
|
/** @use HasFactory<\Database\Factories\WorkspaceFactory> */
|
|
use HasFactory, LogsActivity, SoftDeletes;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'slug',
|
|
];
|
|
|
|
/**
|
|
* Boot the model.
|
|
*/
|
|
protected static function boot(): void
|
|
{
|
|
parent::boot();
|
|
|
|
static::creating(function (Workspace $workspace) {
|
|
if (empty($workspace->slug)) {
|
|
$workspace->slug = Str::slug($workspace->name);
|
|
}
|
|
});
|
|
|
|
static::updating(function (Workspace $workspace) {
|
|
if (empty($workspace->slug)) {
|
|
$workspace->slug = Str::slug($workspace->name);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Get the clients for the workspace.
|
|
*
|
|
* @return HasMany<Client>
|
|
*/
|
|
public function clients(): HasMany
|
|
{
|
|
return $this->hasMany(Client::class);
|
|
}
|
|
|
|
/**
|
|
* Get the declarations for the workspace.
|
|
*
|
|
* @return HasMany<Declaration>
|
|
*/
|
|
public function declarations(): HasMany
|
|
{
|
|
return $this->hasMany(Declaration::class);
|
|
}
|
|
|
|
/**
|
|
* The users that belong to the workspace.
|
|
*
|
|
* @return BelongsToMany<User>
|
|
*/
|
|
public function users(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class, 'workspace_user')
|
|
->using(WorkspaceUser::class)
|
|
->withPivot('role')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logFillable()
|
|
->logOnlyDirty()
|
|
->dontSubmitEmptyLogs();
|
|
}
|
|
}
|