Search code examples
phplaravellaravel-livewirelaravel-filamentfilamentphp

Show table on laravel filament resource edit page


I am on laravel filament and I wanted to show a history of the subscription like Shopify show app history, I am able to fetch the subscription on the index page of the subscription resource but I don't know how can I show a history of the subscription on the tabular format on the view page. Below is the screenshot of how Shopify shows its app history to the users.

shopify app history

Laravel filament subscription history

I have shown all subscription details like this, and I want a table like Shopify to show an app history when I click on a particular record. Thank you


Solution

  • To solve this issue I have created a custom page from filament.

    php artisan make:filament-page SortUsers --resource=UserResource --type=custom

    This command creates two files, one is a class file and the second is a view file. In the class file, I fetched the data with the help of the getViewData() function from the stripe and returned that data to the view file. And in the view file, I have shown that data in a tabular format.

    Steps:-

    Run this command:- php artisan make:filament-page SortUsers --resource=UserResource --type=custom

    <?php
    
    namespace App\Filament\Resources\UserResource\Pages;
    
    use App\Filament\Resources\UserResource;
    use Filament\Resources\Pages\Page;
    
    class SortUsers extends Page
    {
        protected static string $resource = UserResource::class;
    
        protected static string $view = 'filament.resources.user-resource.pages.sort-users';
    
        public function getViewData(): array{
            return $data;
        }
    }
    

    Do a logical code in the getViewData function and return data to the view file.

    In the sort-users.blade.php get the output of the array and print the data

    <x-filament::page>
       {{ $data }}
    </x-filament::page>