Files
ladill-care/app/Models/Department.php
T
isaaccladandCursor 2ac84faf73
Deploy Ladill Care / deploy (push) Successful in 27s
Label multi-branch department picks and add searchable patients.
Make appointment/practitioner department (and practitioner) options show branch names so duplicates are distinguishable, and replace the patient select with a searchable dropdown.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-18 17:31:32 +00:00

46 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use App\Models\Concerns\BelongsToOwner;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class Department extends Model
{
use BelongsToOwner, SoftDeletes;
protected $table = 'care_departments';
protected $fillable = [
'owner_ref', 'branch_id', 'name', 'type', 'is_active',
];
protected function casts(): array
{
return ['is_active' => 'boolean'];
}
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class, 'branch_id');
}
/**
* Select option label — includes branch when set so multi-branch duplicates are distinguishable.
*/
public function labelForSelect(): string
{
$branch = $this->relationLoaded('branch')
? $this->branch
: $this->branch()->first();
if ($branch?->name) {
return $this->name.' — '.$branch->name;
}
return (string) $this->name;
}
}