jeremi_wiecek
Combining values from multiple columns of a relationship into one
Thanks for the answer. Before asking for help, I was using the "state" method, but now I realize I was using it the wrong way. I was calling the column with values "X" and "Y" using:
TextColumn::make('tourLoadingSector')
->label('XY')
->state(function (Tour $record) {
return $record->tourLoadingSector->x . '.' . $record->tourLoadingSector->y;
}),
Executing this code led to an n+1 query problem. The Laravel Debugbar showed about 30 queries when displaying 25 rows in the table. Eventually, I just added the "x" parameter and the problem disappeared!
TextColumn::make('tourLoadingSector.x')
->label('XY')
->state(function (Tour $record) {
return $record->tourLoadingSector->x . '.' . $record->tourLoadingSector->y;
}),
Adding tourLoadingSector.x solved the issue. Apparently, the missing dot with the "x" parameter was needed to clearly indicate the "tourLoadingSector" relationship, rather than just the column name itself. The n+1 query problem went away."
Facepalm 😆 😭3 replies