Files
crewli/api/app/Models/Company.php
bert.hausmans d2f282eb4c feat: split name into first_name + last_name across users, persons, and companies
Cross-cutting migration affecting the entire stack:
- Database: 3 migrations splitting name columns with data migration
- Models: first_name/last_name on User, Person; contact_first_name/contact_last_name on Company; backward-compatible name accessors
- API: all resources return first_name, last_name, full_name; assignablePersons endpoint updated
- Requests: validation rules updated for all person/user/company forms
- Services: VolunteerRegistrationService, ShiftAssignmentService, InvitationService updated
- Frontend: TypeScript types, Zod schemas, all forms split into Voornaam/Achternaam fields
- Display: all person/user name references use full_name; initials use first_name[0]+last_name[0]
- Tests: all 371 tests passing
- Docs: SCHEMA.md and API.md updated

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 23:04:55 +02:00

56 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
final class Company extends Model
{
use HasFactory;
use HasUlids;
use SoftDeletes;
protected $fillable = [
'organisation_id',
'name',
'type',
'contact_first_name',
'contact_last_name',
'contact_email',
'contact_phone',
];
public function getContactFullNameAttribute(): ?string
{
if (! $this->contact_first_name) {
return null;
}
return trim("{$this->contact_first_name} {$this->contact_last_name}");
}
public function organisation(): BelongsTo
{
return $this->belongsTo(Organisation::class);
}
public function persons(): HasMany
{
return $this->hasMany(Person::class);
}
/** @param Builder<self> $query */
public function scopeOrdered(Builder $query): Builder
{
return $query->orderBy('name');
}
}