Skip to content

How to show the data from relationship? #580

Answered by akulmehta
anonymouse703 asked this question in Q&A
Discussion options

You must be logged in to vote

Check this example: https://github.com/Power-Components/powergrid-demo/blob/main/app/Http/Livewire/DishesTable.php

You need to create columns in the addColumns() method. Example:

            /*** KITCHEN ***/
            ->addColumn('kitchen_id', function (Dish $dish) {
                return $dish->kitchen_id;
            })
            ->addColumn('kitchen_name', function (Dish $dish) {
                return $dish->kitchen->name;
            })

next you need to render the columns using the columns() method. Example:

            Column::add()
                ->title(__('Kitchen'))
                ->field('kitchen_name', 'kitchens.name')
                ->sortable('kitchens.name'),

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@anonymouse703
Comment options

Answer selected by anonymouse703
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants