Select Field relationship on edit page

Forms\Components\Select::make('employee_code_with_full_name')
->label(__('cranberry-cookie::cranberry-cookie.form.input.employee_code_with_name'))
->searchable()
->relationship(
name: 'employee',
titleAttribute: 'employee_code_with_full_name',
modifyQueryUsing: function (Builder $query, string $operation) {
$query->where('status',EmployeeStatus::ACTIVE);
})
Forms\Components\Select::make('employee_code_with_full_name')
->label(__('cranberry-cookie::cranberry-cookie.form.input.employee_code_with_name'))
->searchable()
->relationship(
name: 'employee',
titleAttribute: 'employee_code_with_full_name',
modifyQueryUsing: function (Builder $query, string $operation) {
$query->where('status',EmployeeStatus::ACTIVE);
})
it shows emplyee id on edit page but i need to show the employee_code_with_full_name
8 Replies
Dennis Koch
Dennis Koch5mo ago
Please read the #✅┊rules on code formatting
Abinash
AbinashOP5mo ago
yeah, now could you help me ?
Dennis Koch
Dennis Koch5mo ago
That should be the default. Is this a separate column? Or is employee_code_with_full_name a column on your employees table?
Abinash
AbinashOP5mo ago
its the column of employees table
Dennis Koch
Dennis Koch5mo ago
This should probably be employee_id not sure whether that causes issues though: Forms\Components\Select::make('employee_id')
Abinash
AbinashOP5mo ago
i have tried that but it shows employee id not employee_code_with_full_name
LeandroFerreira
LeandroFerreira5mo ago
if you are in the edit page, probably this employee isn't active try
modifyQueryUsing: fn (Builder $query, string $operation) => $query
->when($operation === 'create', fn($query)=> $query->whereStatus(EmployeeStatus::ACTIVE))
modifyQueryUsing: fn (Builder $query, string $operation) => $query
->when($operation === 'create', fn($query)=> $query->whereStatus(EmployeeStatus::ACTIVE))
Abinash
AbinashOP5mo ago
Thanks a lot for your help. I really appreciate it!
Want results from more Discord servers?
Add your server