Files
crewli/api/app/Models/Artist.php
bert.hausmans 9ccf1eaceb feat(timetable): Artist domain — 7 enums + 9 Eloquent models
Enums under App\Enums\Artist\ (PascalCase per FormBuilder convention,
snake_case wire values per RFC):
- ArtistEngagementStatus (D9, 9 states + Dutch labels)
- BumaHandledBy (D26)
- FeeType, PaymentStatus
- AdvanceSectionType, AdvanceSectionSubmissionStatus, AdvanceSubmissionStatus

Models:
- Artist (org-scoped, slug-unique-per-org via creating boot hook)
- ArtistEngagement (per-event booking, denorm organisation_id)
- Genre, Stage (event-scoped, ordered scope), StageDay (Pivot, int PK)
- Performance (engagement-scoped, isParked() helper)
- AdvanceSection, AdvanceSubmission, ArtistContact (primary scope)

OrganisationScope wired:
- Direct organisation_id: Artist, Genre, ArtistEngagement
- FK-chain via tenantScopeStrategy(): Stage→Event, Performance→Engagement,
  AdvanceSection→Engagement, AdvanceSubmission→Section→Engagement,
  ArtistContact→Artist, StageDay→Stage→Event

Soft-deletes: Artist, ArtistEngagement, Performance (per RFC §5.4).
LogsActivity baseline (logFillable+dontSubmitEmptyLogs) on all business
models — actual mutation surfaces wire LogOptions in Session 2+.

Inverse relations added on Organisation, Event, Company.
companies.handles_buma cast added.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 18:00:28 +02:00

108 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Models\Scopes\OrganisationScope;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;
final class Artist extends Model
{
use HasFactory;
use HasUlids;
use LogsActivity;
use SoftDeletes;
protected static function booted(): void
{
self::addGlobalScope(new OrganisationScope);
self::creating(function (Artist $artist): void {
if (empty($artist->slug)) {
$artist->slug = $artist->generateUniqueSlug($artist->name);
}
});
}
protected $fillable = [
'organisation_id',
'name',
'slug',
'default_genre_id',
'default_draw',
'star_rating',
'home_base_country',
'agent_company_id',
'notes',
];
protected function casts(): array
{
return [
'default_draw' => 'integer',
'star_rating' => 'integer',
];
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logFillable()
->dontSubmitEmptyLogs();
}
private function generateUniqueSlug(string $name): string
{
$base = Str::slug($name);
$slug = $base;
$suffix = 2;
while (
self::withoutGlobalScope(OrganisationScope::class)
->withTrashed()
->where('organisation_id', $this->organisation_id)
->where('slug', $slug)
->exists()
) {
$slug = "{$base}-{$suffix}";
$suffix++;
}
return $slug;
}
public function organisation(): BelongsTo
{
return $this->belongsTo(Organisation::class);
}
public function defaultGenre(): BelongsTo
{
return $this->belongsTo(Genre::class, 'default_genre_id');
}
public function agentCompany(): BelongsTo
{
return $this->belongsTo(Company::class, 'agent_company_id');
}
public function contacts(): HasMany
{
return $this->hasMany(ArtistContact::class);
}
public function engagements(): HasMany
{
return $this->hasMany(ArtistEngagement::class);
}
}