Get all the table columns from a resource

Would there be way to get all the columns from a resource?
Solution:
```php protected function getResourceTableColumns(): array { $livewire = app('livewire')->new(ListRecords::class); ...
Jump to solution
15 Replies
BlackShadow
BlackShadowOP9mo ago
Need to get all the table columns from resource for a plugin im working on 🤔
awcodes
awcodes9mo ago
->getTableColumns() probably
BlackShadow
BlackShadowOP9mo ago
I wish👀 Actually this will work on the List page but im currently getting the Resource (in a plugin) then i want to get all the columns of that resource 🤔 Still looking for some help if someone knows how its done 🙂
awcodes
awcodes9mo ago
resource::getTable()->getTableColumns() ?
BlackShadow
BlackShadowOP9mo ago
GetTable expects $table with HasTable 🤔
awcodes
awcodes9mo ago
There has to be a way to grab it, that’s what the list page is doing. Check the ListRecord class
BlackShadow
BlackShadowOP9mo ago
I tried to get it with list record but same thing it requires a livewire component, been going at it for a couple of hours now yikes 😅 Probably need some sleep and give it a fresh pair of eyes tomorrow
awcodes
awcodes9mo ago
That sounds like a plan.
BlackShadow
BlackShadowOP9mo ago
The plugin im working on requires me to get all available data from a table resource so if i cant get that then its game over💀
awcodes
awcodes9mo ago
We’ll figure it out. Get some sleep.
dissto
dissto9mo ago
I give up for today too. Can't seem to get past that it requires Table $table for everything I tried 🤌
BlackShadow
BlackShadowOP9mo ago
Same
Dennis Koch
Dennis Koch9mo ago
Sounds like you want something like (untested):
$table = new Table()
YourResource::table($table);
$table->getColumns();
$table = new Table()
YourResource::table($table);
$table->getColumns();
BlackShadow
BlackShadowOP9mo ago
Tried many of these variants can't seem to get it to work 😵‍💫 @dissto also tried a fair bit.
Solution
BlackShadow
BlackShadow9mo ago
protected function getResourceTableColumns(): array
{
$livewire = app('livewire')->new(ListRecords::class);

return YourResource::table(new Table($livewire))->getColumns();
}
protected function getResourceTableColumns(): array
{
$livewire = app('livewire')->new(ListRecords::class);

return YourResource::table(new Table($livewire))->getColumns();
}
Want results from more Discord servers?
Add your server