badge with link and show name instead id

Hello everyone! Have a nice weekend! I want to ask about my code here below
Tables\Columns\TextColumn::make('inventory_location_list.inventory_location.id')
->searchable()
->badge()
->url(function ($state): string {
return InventoryLocationResource::getUrl('edit', ['record' => $state[0]]);
})
->separator(',')
->label('At Room'),
Tables\Columns\TextColumn::make('inventory_location_list.inventory_location.id')
->searchable()
->badge()
->url(function ($state): string {
return InventoryLocationResource::getUrl('edit', ['record' => $state[0]]);
})
->separator(',')
->label('At Room'),
firstly I want to make each badge from the relationship have a link, not only 1 link but multiple links from how much data from the relationship second, I want to show
inventory_location.room_name
inventory_location.room_name
instead
inventory_location.id
inventory_location.id
but still want to get the id for link the URL each badge how can I do that? Thank you!
Solution:
and the record will give you the entire model instance that you can extract the correct data from
Jump to solution
3 Replies
Dan Harrin
Dan Harrin2mo ago
use room_name instead of the id in the column name then in url(), pass $record instead of $state
Solution
Dan Harrin
Dan Harrin2mo ago
and the record will give you the entire model instance that you can extract the correct data from
thyk123
thyk1232mo ago
Thank you for the respond! Glad for the help it works, but i stuck when access the relation
$record->inventory_location_list->inventory_location
$record->inventory_location_list->inventory_location
it says there is no eleqouent, and tries to dd to the
$record->inventory_location_list
$record->inventory_location_list
it show the eloqeunt but added
->inventory_location
->inventory_location
not show the eloquent only relationship, how i can access that?
Missing required parameters for [Route: filament.admin.resources.inventory-locations.edit] [URI: admin/inventory-locations/{record}/edit] [Missing parameters: "id":1,"inventory_location_id":"01hxgz0mfew7f82z6ss0e82egw","inventory_id":"01hxgy0f0z96rbppw5jqgg552a","status":"Excellent","qty":"1","note":null,"created_at":"2024-05-10T10:43:04.000000Z","updated_at":"2024-05-10T10:43:04.000000Z","deleted_at":null,"inventory_location":{"id":"01hxgz0mfew7f82z6ss0e82egw","room_name":"room test","room_status":"occupied","occupied_by":"test","user_id":1,"deleted_at":null,"created_at":"2024-05-10T09:58:10.000000Z","updated_at":"2024-05-10T09:58:10.000000Z", "id":2,"inventory_location_id":"01hxgyzb4mv113ja5fd37h81h2","inventory_id":"01hxgy0f0z96rbppw5jqgg552a","status":"good","qty":"1","note":null,"created_at":"2024-05-10T12:46:22.000000Z","updated_at":"2024-05-10T12:46:22.000000Z","deleted_at":null,"inventory_location":{"id":"01hxgyzb4mv113ja5fd37h81h2","room_name":"room test 2","room_status":"occupied","occupied_by":"test","user_id":1,"deleted_at":null,"created_at":"2024-05-10T09:57:28.000000Z","updated_at":"2024-05-10T12:46:22.000000Z"].
Missing required parameters for [Route: filament.admin.resources.inventory-locations.edit] [URI: admin/inventory-locations/{record}/edit] [Missing parameters: "id":1,"inventory_location_id":"01hxgz0mfew7f82z6ss0e82egw","inventory_id":"01hxgy0f0z96rbppw5jqgg552a","status":"Excellent","qty":"1","note":null,"created_at":"2024-05-10T10:43:04.000000Z","updated_at":"2024-05-10T10:43:04.000000Z","deleted_at":null,"inventory_location":{"id":"01hxgz0mfew7f82z6ss0e82egw","room_name":"room test","room_status":"occupied","occupied_by":"test","user_id":1,"deleted_at":null,"created_at":"2024-05-10T09:58:10.000000Z","updated_at":"2024-05-10T09:58:10.000000Z", "id":2,"inventory_location_id":"01hxgyzb4mv113ja5fd37h81h2","inventory_id":"01hxgy0f0z96rbppw5jqgg552a","status":"good","qty":"1","note":null,"created_at":"2024-05-10T12:46:22.000000Z","updated_at":"2024-05-10T12:46:22.000000Z","deleted_at":null,"inventory_location":{"id":"01hxgyzb4mv113ja5fd37h81h2","room_name":"room test 2","room_status":"occupied","occupied_by":"test","user_id":1,"deleted_at":null,"created_at":"2024-05-10T09:57:28.000000Z","updated_at":"2024-05-10T12:46:22.000000Z"].