Table Relationship 'name' not 'id'
Apologies if this has been asked before but I can seem to find the solution in the docs or in Discord.
Currently, when viewing records using the table builder, I can see a column's relationship's
id
but I want it to display the relationship's name
column.
The model's relationship:
Here is what I've tried:
TextColumn::make('resort.resort'),
this results in SQLSTATE[42S22]: Column not found: 1054 Unknown column 'resorts.resort' in 'where clause'
I've also tried:
TextColumn::make('resorts.resort'),
and the table column is blank
this just outputs the id
TextColumn::make('resort'),
9 Replies
The relationship model is fine, I can get the names of the relationship in the Editor, but only their
id
shows up in the main list view.
Here's an example:
- First screen shot is the list (table) view.
- Second screen shot is the edit view.try
resort is the relation & the name is the column name
Tried that prior, and this is what it results in:
Code for reference:
If it helps, here is the migration:
$table->foreignId('resort')->nullable()->constrained()->references('id')->on('resorts');
If possible, try to rename the foreignId to resort_id and see how it goes. So the table column will be resort_id
No luck still. The
id
of the relationship is still being output.I got the same problem. In that the relationships are fine but to display a name from the column relationship is a problem. Does not display anything.
If you reference .name do you get that there is no relationship error or no error at all?
please show the entire model (if you can) and the entire component
Did you find a solution