Problem editing filtered record
Hi guys. I hope someone can help me.
I have a table with data that is filtered before loading based on the role of the logged in user. In this way, the user only sees the records that he/she must manage. The query I use is the following:
public static function getEloquentQuery(): Builder
{
if (Auth::user()->hasRole('panel_user')) {
return parent::getEloquentQuery()->where('modality', 'TF');
} elseif (Auth::user()->hasRole('panel_user_presencial')) {
return parent::getEloquentQuery()->where('modality', '=','P')->Orwhere('modality', '=', 'M')->Orwhere('modality', '=', 'AV');
} else {
return parent::getEloquentQuery();
}
}
Los datos obtenidos son correctos para cada usuario, el problema ocurre cuando se intenta editar un registro, siempre edita el primero de la lista independientemente del que pulse.
Why does this happen? How can I solve it?
Thanks in advance
I have a table with data that is filtered before loading based on the role of the logged in user. In this way, the user only sees the records that he/she must manage. The query I use is the following:
public static function getEloquentQuery(): Builder
{
if (Auth::user()->hasRole('panel_user')) {
return parent::getEloquentQuery()->where('modality', 'TF');
} elseif (Auth::user()->hasRole('panel_user_presencial')) {
return parent::getEloquentQuery()->where('modality', '=','P')->Orwhere('modality', '=', 'M')->Orwhere('modality', '=', 'AV');
} else {
return parent::getEloquentQuery();
}
}
Los datos obtenidos son correctos para cada usuario, el problema ocurre cuando se intenta editar un registro, siempre edita el primero de la lista independientemente del que pulse.
Why does this happen? How can I solve it?
Thanks in advance
Solution
Hello
I have used the modifyQueryUsing() function on the table and the records it displays for each user are correct, however when editing a record the information it loads is still incorrect, that is, it always loads the information from the first record shown regardless of the one you select.
Example:
->modifyQueryUsing(function (Builder $query) {
if (Auth::user()->hasRole('panel_user')) {
return $query->where('modality', 'TF');
} elseif (Auth::user()->hasRole('panel_user_presencial')) {
return $query->where('modality', '=','P')->Orwhere('modality', '=', 'M')->Orwhere('modality', '=', 'AV');
}
})
I have observed that the id of the record that is loaded for editing is correct but the information is not.
What could be the cause of this?
Regards.
I have used the modifyQueryUsing() function on the table and the records it displays for each user are correct, however when editing a record the information it loads is still incorrect, that is, it always loads the information from the first record shown regardless of the one you select.
Example:
->modifyQueryUsing(function (Builder $query) {
if (Auth::user()->hasRole('panel_user')) {
return $query->where('modality', 'TF');
} elseif (Auth::user()->hasRole('panel_user_presencial')) {
return $query->where('modality', '=','P')->Orwhere('modality', '=', 'M')->Orwhere('modality', '=', 'AV');
}
})
I have observed that the id of the record that is loaded for editing is correct but the information is not.
What could be the cause of this?
Regards.