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 Koch4mo ago
Please read the #✅┊rules on code formatting
Abinash
Abinash4mo ago
yeah, now could you help me ?
Dennis Koch
Dennis Koch4mo 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
Abinash4mo ago
its the column of employees table
Dennis Koch
Dennis Koch4mo ago
This should probably be employee_id not sure whether that causes issues though: Forms\Components\Select::make('employee_id')
Abinash
Abinash4mo ago
i have tried that but it shows employee id not employee_code_with_full_name
LeandroFerreira
LeandroFerreira4mo 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
Abinash4mo ago
Thanks a lot for your help. I really appreciate it!
Want results from more Discord servers?
Add your server