public static function form(Form $form): Form
{
dd(auth()->user()->doctor->id, Auth::user());
return $form
->schema([
Forms\Components\TextInput::make('title')
->required()
->maxLength(255),
Forms\Components\Textarea::make('content')
->required()
->columnSpanFull(),
Forms\Components\Select::make('patient_id')
->label('Patient')
->options(function () {
// load patients with their user to build the label
return Patient::with('user')
->get()
->mapWithKeys(function ($patient) {
$user = $patient->user;
$label = $user
? trim(($user->first_name ?? '') . ' ' . ($user->last_name ?? '') ?: ($user->name ?? 'Unknown'))
: 'Unknown';
return [$patient->id => $label];
})->toArray();
})
->searchable() // enables filtering in the select dropdown
->required(),
Hidden::make('doctor_id')
->default(fn() => auth()->user()->doctor->id)
->hidden()
// ->relationship('doctor', 'id')
->required(),
])
->columns(1);
}
public static function form(Form $form): Form
{
dd(auth()->user()->doctor->id, Auth::user());
return $form
->schema([
Forms\Components\TextInput::make('title')
->required()
->maxLength(255),
Forms\Components\Textarea::make('content')
->required()
->columnSpanFull(),
Forms\Components\Select::make('patient_id')
->label('Patient')
->options(function () {
// load patients with their user to build the label
return Patient::with('user')
->get()
->mapWithKeys(function ($patient) {
$user = $patient->user;
$label = $user
? trim(($user->first_name ?? '') . ' ' . ($user->last_name ?? '') ?: ($user->name ?? 'Unknown'))
: 'Unknown';
return [$patient->id => $label];
})->toArray();
})
->searchable() // enables filtering in the select dropdown
->required(),
Hidden::make('doctor_id')
->default(fn() => auth()->user()->doctor->id)
->hidden()
// ->relationship('doctor', 'id')
->required(),
])
->columns(1);
}