feat: fase 2 backend — crowd types, persons, sections, shifts, invite flow
- Crowd Types + Persons CRUD (73 tests) - Festival Sections + Time Slots + Shifts CRUD met assign/claim flow (84 tests) - Invite Flow + Member Management met InvitationService (109 tests) - Schema v1.6 migraties volledig uitgevoerd - DevSeeder bijgewerkt met crowd types voor testorganisatie
This commit is contained in:
91
api/app/Models/Person.php
Normal file
91
api/app/Models/Person.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
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\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
final class Person extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasUlids;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'persons';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'event_id',
|
||||
'crowd_type_id',
|
||||
'company_id',
|
||||
'name',
|
||||
'email',
|
||||
'phone',
|
||||
'status',
|
||||
'is_blacklisted',
|
||||
'admin_notes',
|
||||
'custom_fields',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_blacklisted' => 'boolean',
|
||||
'custom_fields' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function event(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Event::class);
|
||||
}
|
||||
|
||||
public function crowdType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CrowdType::class);
|
||||
}
|
||||
|
||||
public function company(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function crowdLists(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(CrowdList::class, 'crowd_list_persons')
|
||||
->withPivot('added_at', 'added_by_user_id');
|
||||
}
|
||||
|
||||
public function shiftAssignments(): HasMany
|
||||
{
|
||||
return $this->hasMany(ShiftAssignment::class);
|
||||
}
|
||||
|
||||
public function scopeApproved(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'approved');
|
||||
}
|
||||
|
||||
public function scopePending(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'pending');
|
||||
}
|
||||
|
||||
public function scopeForCrowdType(Builder $query, string $type): Builder
|
||||
{
|
||||
return $query->whereHas('crowdType', fn (Builder $q) => $q->where('system_type', $type));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user