$record->relationship->fieldData not working

I have a resource for persona (People in Spanish) and I am showing a column which comes from a relationship and it is working correctly.
TextColumn::make('interviniente.tipoExpediente')
->label('TipoExp')
TextColumn::make('interviniente.tipoExpediente')
->label('TipoExp')
Now I need to make an action which will redirect to a different URL depending on the value in that columns TipoExp. I have tried this:
->url(function (Persona $record){

switch ($record->tipoExp)
{
case 'Herencia':
return 'expedientes-herencia/' . $record->id;
break;
case 'Compra-Venta':
...
->url(function (Persona $record){

switch ($record->tipoExp)
{
case 'Herencia':
return 'expedientes-herencia/' . $record->id;
break;
case 'Compra-Venta':
...
But it is returning nothing. It looks as if $record->tipoExp has nothing inside. I have also tried to access through the related relationship, but it is not working either:
switch ($record->interviniente->tipoExpediente)
switch ($record->interviniente->tipoExpediente)
Not working either. How could I solve this, please??
1 Reply
gustavo.dev
gustavo.dev2mo ago
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Actions\Action;
use App\Models\Persona;

TextColumn::make('interviniente.tipoExpediente')
->label('TipoExp');

Action::make('redirect')
->url(fn (Persona $record) => match($record->interviniente->tipoExpediente) {
'Herencia' => url('expedientes-herencia/' . $record->id),
'Compra-Venta' => url('expedientes-compra-venta/' . $record->id),
default => url('expedientes/' . $record->id),
});
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Actions\Action;
use App\Models\Persona;

TextColumn::make('interviniente.tipoExpediente')
->label('TipoExp');

Action::make('redirect')
->url(fn (Persona $record) => match($record->interviniente->tipoExpediente) {
'Herencia' => url('expedientes-herencia/' . $record->id),
'Compra-Venta' => url('expedientes-compra-venta/' . $record->id),
default => url('expedientes/' . $record->id),
});
Want results from more Discord servers?
Add your server