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.
No description
No description
No description
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" 😉...
Jump to solution
19 Replies
DrByte
DrByte10mo ago
That's because your Edit form Select field is looking at the relationship, but your table is looking only at the ID column.
Yurikaso
Yurikaso10mo ago
Hello love again ! I'm new at this and I would like to learn 😄 How do I fix it? jeje
DrByte
DrByte10mo ago
Please post the code of your Form
Yurikaso
Yurikaso10mo ago
I added the database tables, but it's very simple really
No description
No description
Yurikaso
Yurikaso10mo ago
and the model, but I have no idea jejejej
No description
DrByte
DrByte10mo ago
In your $table, instead of ::make('contacto_id') try ::make('contacto.nombre')
Yurikaso
Yurikaso10mo ago
does not work this error is displayed
No description
Yurikaso
Yurikaso10mo ago
and this is how it appears in the database
No description
DrByte
DrByte10mo ago
In your Ordenes model you might need to be specific about the HasMany relationship column names. Perhaps this:
public function contacto(): HasMany
{
return $this->hasMany(Contactos::class, 'id', 'contactos_id');
}
public function contacto(): HasMany
{
return $this->hasMany(Contactos::class, 'id', 'contactos_id');
}
Yurikaso
Yurikaso10mo ago
now comes out blank 😮
No description
DrByte
DrByte10mo ago
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?
Yurikaso
Yurikaso10mo ago
No description
No description
No description
Yurikaso
Yurikaso10mo ago
there are the db table, the model, and the resource
DrByte
DrByte10mo ago
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:
public function contacto(): BelongsTo
{
return $this->belongsTo(Contactos::class, 'contactos_id');
}
public function contacto(): BelongsTo
{
return $this->belongsTo(Contactos::class, 'contactos_id');
}
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.
Yurikaso
Yurikaso10mo ago
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
DrByte
DrByte10mo ago
Excellent!
Solution
DrByte
DrByte10mo ago
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" 😉
cheesegrits
cheesegrits10mo ago
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.
DrByte
DrByte10mo ago
Oh Hugh, you're really still just 29 at heart!
Want results from more Discord servers?
Add your server
More Posts