I get the ID number in the column and not the name
I don't understand why I get a value in the select but not in the table.
Solution:Jump to solution
Can you also mark this thread as solved? Right-click on the post that is the "correct answer", and choose "Apps->MarkSolution".
That helps people know which posts are "done" vs which ones "still need help" 😉...
19 Replies
That's because your Edit form Select field is looking at the relationship, but your table is looking only at the ID column.
Hello love again ! I'm new at this and I would like to learn 😄
How do I fix it? jeje
Please post the code of your Form
I added the database tables, but it's very simple really
and the model, but I have no idea jejejej
In your $table, instead of
::make('contacto_id')
try ::make('contacto.nombre')
does not work this error is displayed
and this is how it appears in the database
In your Ordenes model you might need to be specific about the HasMany relationship column names. Perhaps this:
now comes out blank 😮
I don't think this is a Filament problem. It's with the relations you've set up in Laravel. I think you're not using the column names that Laravel expects as defaults, and therefore you need to manually specify the custom column names in your HasMany/BelongsTo/etc relations
What's the schema for your Contactos table?
there are the db table, the model, and the resource
Tip: in future, please post code in code tags, not as images. It's impossible to copy/paste your code from an image, which means it's not easy to test it out or to post it back to you with corrections. To post code you can use the same markdown syntax as for github etc: three backtick symbols on their own line, at the beginning of your code, and then after your code three more backtick symbols on their own line. You'll see in Discord that it'll immediately show you how it's treating it as code.
I think there's more explanation of this in the #✅┊rules section.
Now, that aside, lemme explain what Filament is doing, based on what you've posted so far:
Explanation: Back in your first post you said that your table is showing the ID numbers. That's because your $table definition is directly displaying the
contacto_id
, vehiculo_id
, and servicio_id
data from your orderes
table. It's just reading the table data directly and displaying it back to you.
But you want it to display the name that's in the db table defined by the Model's relations.
Your orderes.contacto_id
field corresponds to your contactos.id
field, so your Laravel relation inside the Orderes
model must define a relationship.
I think the correct relationship here (in the Orderes model) should be BelongsTo, not HasMany
So, in Orderes, you need:
And then in your $table, instead of contactos_id
use contacto.nombre
so that it looks to the contactos table for the nombre column. ("contacto.nombre" means "look in the Orderes model for the contacto() relationship, which points to the Contactos table, and retrieve the "nombre" value based on the "contactos_id" from the orderes table)
I think it's just that you had the wrong relationship type defined.ok I'll try to fix it thank you very much
´´ <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Ordenes extends Model
{
use HasFactory;
protected $fillable = ['contacto_id', 'vehiculo_id', 'servicio_id', 'fecha', 'estado', 'comentario'];
public function contacto(): BelongsTo
{
return $this->belongsTo(Contactos::class);
}
public function servicio(): BelongsTo
{
return $this->belongsTo(Servicios::class);
}
public function vehiculo(): BelongsTo
{
return $this->belongsTo(Vehiculos::class);
}
}
´´
there is the solution thanks
Excellent!
Solution
Can you also mark this thread as solved? Right-click on the post that is the "correct answer", and choose "Apps->MarkSolution".
That helps people know which posts are "done" vs which ones "still need help" 😉
Another thing I will add about screenshots of code is that some of us are old farts (OK, me, I'm an old fart) and I literally cannot read the code in screenshots, without opening the image in a browser and zooming in on it. Which I can't be arsed to do. So I don't help people who post screesnshots of code.
Oh Hugh, you're really still just 29 at heart!