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
BlackShadow4mo ago
Need to get all the table columns from resource for a plugin im working on 🤔
awcodes
awcodes4mo ago
->getTableColumns() probably
BlackShadow
BlackShadow4mo 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
awcodes4mo ago
resource::getTable()->getTableColumns() ?
BlackShadow
BlackShadow4mo ago
GetTable expects $table with HasTable 🤔
awcodes
awcodes4mo ago
There has to be a way to grab it, that’s what the list page is doing. Check the ListRecord class
BlackShadow
BlackShadow4mo 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
awcodes4mo ago
That sounds like a plan.
BlackShadow
BlackShadow4mo 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
awcodes4mo ago
We’ll figure it out. Get some sleep.
dissto
dissto4mo ago
I give up for today too. Can't seem to get past that it requires Table $table for everything I tried 🤌
BlackShadow
BlackShadow4mo ago
Same
Dennis Koch
Dennis Koch4mo 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
BlackShadow4mo ago
Tried many of these variants can't seem to get it to work 😵‍💫 @dissto also tried a fair bit.
Solution
BlackShadow
BlackShadow4mo 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
More Posts