### Install Filament Table Layout Toggle Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Install the package using Composer and optionally publish the views and configuration files. ```bash composer require hydrat/filament-table-layout-toggle:^4.0 # Publish views (optional) php artisan vendor:publish --tag="table-layout-toggle-views" # Publish config (required for standalone tables, not needed for panels) php artisan vendor:publish --tag="table-layout-toggle-config" ``` -------------------------------- ### Install Filament Table Layout Toggle Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Install the package using Composer. Ensure you meet the PHP, Laravel, and Filament version requirements. ```bash composer require hydrat/filament-table-layout-toggle:^4.0 ``` -------------------------------- ### Standalone Configuration File Example Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Configure all plugin settings via the `config/table-layout-toggle.php` file when used outside of a Filament panel. This includes default layout, mobile layout, toggle action settings, and persistence options. ```php // config/table-layout-toggle.php use Hydrat\TableLayoutToggle\Persisters; return [ 'default_layout' => 'list', // 'list' or 'grid' 'auto_mobile_layout' => false, 'toggle_action' => [ 'enabled' => true, 'position' => 'tables::toolbar.search.after', // Filament render hook 'list_icon' => 'heroicon-s-list-bullet', 'grid_icon' => 'heroicon-s-squares-2x2', ], 'persist' => [ 'persiter' => Persisters\LocalStoragePersister::class, 'cache' => [ 'store' => null, // null = use config('cache.default') 'time' => 60 * 24 * 7, // TTL in minutes (default: 1 week) ], 'share_between_pages' => false, // true = one toggle state for all tables ], ]; ``` -------------------------------- ### Create a Custom Layout Persister Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Example of creating a custom layout persister by extending `AbstractPersister` and implementing the `LayoutPersister` contract. This allows for custom state saving and retrieval logic. ```php getKey(), $layoutState); return $this; } public function getState(): ?string { return persisterGetState($this->getKey()); } public function onComponentBoot(): void { // add filament hooks to render a custom view or so... } } ``` -------------------------------- ### Get Custom Toggle Table Actions Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Retrieve and utilize custom toggle actions using the `TableLayoutToggle` facade. Examples show how to add actions to table headers or Filament page headers. ```php use Hydrat\TableLayoutToggle\Facades\TableLayoutToggle; # eg: Display action on top of the table : return $table ->columns(...) ->headerActions([ TableLayoutToggle::getToggleViewTableAction(compact: true), ]); # eg: As Filament page header action : protected function getHeaderActions(): array { return [ TableLayoutToggle::getToggleViewAction(compact: false) ->hiddenLabel(false) ->label('Toggle layout'), ]; } ``` -------------------------------- ### Implement Custom Database Layout Persister Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Extend AbstractPersister and implement LayoutPersister to create a custom database persistence strategy. This example shows how to save and retrieve layout states using database queries. ```php where('user_id', auth()->id()) ->where('key', $this->getKey()) ->value('value'); } public function setState(string $layoutState): self { \DB::table('user_preferences')->updateOrInsert( ['user_id' => auth()->id(), 'key' => $this->getKey()], ['value' => $layoutState, 'updated_at' => now()], ); return $this; } } // Register: TableLayoutTogglePlugin::make() ->persistLayoutUsing(\App\Filament\Persisters\DatabasePersister::class); ``` -------------------------------- ### Conditional Column Rendering with isGridLayout() and isListLayout() Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Use these helper methods within your table definition to conditionally render different column sets based on the active layout. This example shows how to define grid and list columns and apply them based on the layout. ```php use Filament\Tables\Columns\Layout\Split; use Filament\Tables\Columns\Layout\Stack; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; public static function table(Table $table): Table { /** @var \Hydrat\TableLayoutToggle\Concerns\HasToggleableTable $livewire */ $livewire = $table->getLivewire(); return $table ->columns( $livewire->isGridLayout() ? static::getGridColumns() : static::getListColumns() ) ->contentGrid( fn () => $livewire->isListLayout() ? null : ['md' => 2, 'lg' => 3, 'xl' => 4] ); } private static function getListColumns(): array { return [ TextColumn::make('name')->sortable()->searchable(), TextColumn::make('email')->sortable(), TextColumn::make('created_at')->dateTime()->sortable(), ]; } private static function getGridColumns(): array { return [ Stack::make([ TextColumn::make('name') ->description(__('Name'), position: 'above') ->searchable(), Split::make([ TextColumn::make('email') ->description(__('Email'), position: 'above'), TextColumn::make('created_at') ->dateTime() ->description(__('Joined'), position: 'above'), ]), ])->space(3), ]; } ``` -------------------------------- ### Customizing Layout Persister with configurePersister() Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Override this method in components using `HasToggleableTable` to adjust or replace the layout persister for a specific table. This example customizes the key, cache driver, and expiration for the layout persister. ```php use Hydrat\TableLayoutToggle\Concerns\HasToggleableTable; use Hydrat\TableLayoutToggle\Persisters\CachePersister; class ListOrders extends ListRecords { use HasToggleableTable; public function getDefaultLayoutView(): string { return 'grid'; // always start in grid for this table } public function configurePersister(): void { // Customize the existing persister for this table $this->layoutPersister ->setKey('orders_layout_' . auth()->id()) ->setCacheDriver('redis') ->setExpiration(60 * 24 * 30); // 30 days // Or swap to a completely different persister class // $this->layoutPersister = new CachePersister($this); } } ``` -------------------------------- ### Publish Table Layout Toggle Views Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Optionally publish the package's views to customize their appearance. This command is for general view publishing. ```bash php artisan vendor:publish --tag="table-layout-toggle-views" ``` -------------------------------- ### Configure Cache Persister Options Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Demonstrates how to configure the Cache persister with custom storage and TTL. Use the `persistLayoutUsing` method for plugins or the configuration file for standalone tables. ```php // Plugin registration TableLayoutTogglePlugin::make() ->persistLayoutUsing( persister: Persisters\CachePersister::class, cacheStore: 'redis', // change storage to redis cacheTtl: 60 * 24 * 7 * 4, // change ttl to 1 month ); ``` ```php // Configuration file 'persiter' => Persisters\CachePersister::class, 'cache' => [ 'storage' => 'redis', // change storage to redis 'time' => 60 * 24 * 7 * 4, // change ttl to 1 month ], ``` -------------------------------- ### Publish Table Layout Toggle Configuration Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Publish the configuration file if you are using this package for standalone tables outside of Filament panels. This file is ignored when used within panels. ```bash php artisan vendor:publish --tag="table-layout-toggle-config" ``` -------------------------------- ### Define Grid Table Columns with Layouts Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Define the columns for the grid layout using Filament's layout components like `Stack` and `Split`. Use `TextColumn::make()` with `description()` for labels. ```php use Filament\Tables\Columns\Layout\Split; use Filament\Tables\Columns\Layout\Stack; use Filament\Tables\Columns\TextColumn; public static function getGridTableColumns(): array { return [ // Make sure to stack your columns together Stack::make([ TextColumn::make('status')->badge(), // You may group columns together using the Split layout, so they are displayed side by side Split::make([ TextColumn::make('customer') ->description(__('Customer'), position: 'above') ->searchable(), TextColumn::make('owner.name') ->description(__('Owner'), position: 'above') ->searchable(), ]), ])->space(3)->extraAttributes([ 'class' => 'pb-2', ]), ]; } ``` -------------------------------- ### Dynamically Configure Table Columns by Layout Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Configure the `table()` method to dynamically set columns based on the current layout (grid or list). Use `isGridLayout()` and `isListLayout()` from the `HasToggleableTable` trait. The `contentGrid` option can be set to define grid breakpoints. ```php public static function table(Table $table): Table { /** @var \Hydrat\TableLayoutToggle\Concerns\HasToggleableTable $livewire */ $livewire = $table->getLivewire(); return $table ->columns( $livewire->isGridLayout() ? static::getGridTableColumns() : static::getListTableColumns() ) ->contentGrid( fn () => $livewire->isListLayout() ? null : [ 'md' => 2, 'lg' => 3, 'xl' => 4, ] ) ->filters([ // ]); } // Define the columns for the table when displayed in list layout public static function getListTableColumns(): array; // Define the columns for the table when displayed in grid layout public static function getGridTableColumns(): array; ``` -------------------------------- ### Register Plugin on Filament Panel Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Register the TableLayoutTogglePlugin on a Filament panel provider. Configuration methods are chainable and optional, with default values provided. ```php use Hydrat\TableLayoutToggle\TableLayoutTogglePlugin; use Hydrat\TableLayoutToggle\Persisters; public function panel(Panel $panel): Panel { return $panel ->plugins([ TableLayoutTogglePlugin::make() ->setDefaultLayout('list') // 'list' (default) or 'grid' ->persistLayoutUsing( persister: Persisters\LocalStoragePersister::class, // default cacheStore: 'redis', // only used with CachePersister cacheTtl: 60 * 24 * 7, // minutes; only used with CachePersister ) ->shareLayoutBetweenPages(false) // true = one global toggle per user ->displayToggleAction(true) // auto-render toggle button ->toggleActionHook('tables::toolbar.search.after') // Filament render hook ->listLayoutButtonIcon('heroicon-o-list-bullet') ->gridLayoutButtonIcon('heroicon-o-squares-2x2') ->enableAutoMobileLayout(), // grid by default on mobile ]); } ``` -------------------------------- ### Register Filament Table Layout Toggle Plugin Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Register the plugin in your Filament panel configuration. Customize default layout, persistence, and toggle action behavior. ```php use Hydrat\TableLayoutToggle\TableLayoutTogglePlugin; public function panel(Panel $panel): Panel { return $panel ->plugins([ TableLayoutTogglePlugin::make() ->setDefaultLayout('grid') // default layout for user seeing the table for the first time ->persistLayoutUsing( persister: \Hydrat\TableLayoutToggle\Persisters\LocalStoragePersister::class, // chose a persister to save the layout preference of the user cacheStore: 'redis', // optional, change the cache store for the Cache persister cacheTtl: 60 * 24, // optional, change the cache time for the Cache persister ) ->shareLayoutBetweenPages(false) // allow all tables to share the layout option for this user ->displayToggleAction() // used to display the toggle action button automatically ->toggleActionHook('tables::toolbar.search.after') // chose the Filament view hook to render the button on ->listLayoutButtonIcon('heroicon-o-list-bullet') ->gridLayoutButtonIcon('heroicon-o-squares-2x2') ->enableAutoMobileLayout(), // automatically use grid layout for mobile users with no saved preference ]); } ``` -------------------------------- ### Layout Persister Classes Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Specifies the available persister classes for saving user layout preferences. Choose LocalStorage, Cache, or Disabled. ```php Hydrat\TableLayoutToggle\Persisters\LocalStoragePersister::class # Save the layout in the local storage ``` ```php Hydrat\TableLayoutToggle\Persisters\CachePersister::class # Save the layout in the application cache ``` ```php Hydrat\TableLayoutToggle\Persisters\DisabledPersister::class # Do not persist the layout ``` -------------------------------- ### Use TableLayoutToggle Facade for Custom Toggle Actions Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Utilize the TableLayoutToggle facade to obtain a pre-configured Action instance for placing the toggle button in custom locations within a Filament panel, such as table headers or page headers. ```php use Hydrat\TableLayoutToggle\Facades\TableLayoutToggle; // As a table header action (inline with the table toolbar): public static function table(Table $table): Table { return $table ->columns([/* ... */]) ->headerActions([ TableLayoutToggle::getToggleViewAction(compact: true), ]); } // As a Filament page header action: protected function getHeaderActions(): array { return [ TableLayoutToggle::getToggleViewAction(compact: false) ->hiddenLabel(false) ->label('Switch Layout') ->color('primary'), ]; } // Disable the automatic toggle rendering first if using a custom placement: TableLayoutTogglePlugin::make() ->displayToggleAction(false), // stop auto-rendering ``` -------------------------------- ### Configure Table Schema Dynamically Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Dynamically set the table schema based on the selected layout within your resource's Table class. Use `isGridLayout()` and `isListLayout()` to conditionally render columns and content grids. ```php class EntriesTable { public static function configure(Table $table): Table { /** @var \Hydrat\TableLayoutToggle\Concerns\HasToggleableTable $livewire */ $livewire = $table->getLivewire(); return $table ->columns( $livewire->isGridLayout() ? static::getGridTableColumns() : static::getListTableColumns() ) ->contentGrid( fn () => $livewire->isListLayout() ? null : [ 'md' => 2, 'lg' => 3, 'xl' => 4, ] ) ->filters([ // ]); } // Define the columns for the table when displayed in list layout public static function getListTableColumns(): array; // Define the columns for the table when displayed in grid layout public static function getGridTableColumns(): array; } ``` -------------------------------- ### Configuring DisabledPersister for Filament Tables Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Configure the `DisabledPersister` for the Filament Table Layout Toggle plugin to disable persistence entirely. The layout will always reset to the default on page load. ```php TableLayoutTogglePlugin::make() ->persistLayoutUsing( persister: \Hydrat\TableLayoutToggle\Persisters\DisabledPersister::class, ); ``` -------------------------------- ### Configuring LocalStoragePersister for Filament Tables Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Configure the `LocalStoragePersister` for the Filament Table Layout Toggle plugin. This is the default persister and stores layout preferences in the browser's localStorage. ```php // Panel plugin TableLayoutTogglePlugin::make() ->persistLayoutUsing( persister: \Hydrat\TableLayoutToggle\Persisters\LocalStoragePersister::class, ); // Standalone config (config/table-layout-toggle.php) 'persist' => [ 'persiter' => \Hydrat\TableLayoutToggle\Persisters\LocalStoragePersister::class, ], // For standalone Livewire tables, render the persister script in your Blade view: // {{ $this->table }} // {{ $this->renderLayoutViewPersister() }} ``` -------------------------------- ### Configuring CachePersister for Filament Tables Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Configure the `CachePersister` for the Filament Table Layout Toggle plugin to save layout preferences server-side using Laravel's cache system. This is useful for SSR or cross-device synchronization. ```php // Panel plugin TableLayoutTogglePlugin::make() ->persistLayoutUsing( persister: \Hydrat\TableLayoutToggle\Persisters\CachePersister::class, cacheStore: 'redis', cacheTtl: 60 * 24 * 7, // 1 week in minutes ); // Standalone config 'persist' => [ 'persiter' => \Hydrat\TableLayoutToggle\Persisters\CachePersister::class, 'cache' => [ 'store' => 'redis', 'time' => 60 * 24 * 7, ], ] ``` -------------------------------- ### Configure Per-Table Settings Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Override default layout settings for a specific table by defining `getDefaultLayoutView` and `configurePersister` methods in your Livewire component. This allows for table-specific configurations. ```php namespace App\Livewire\Users; use Illuminate\Http\Request; use Filament\Forms\Contracts\HasForms; use Filament\Tables\Contracts\HasTable; use Livewire\Component; use Hydrat\TableLayoutToggle\Traits\HasToggleableTable; class ListUsers extends Component implements HasForms, HasTable { use HasToggleableTable; /** * Set the default layout for this table, when the user sees it for the first time. */ public function getDefaultLayoutView(): string { return 'grid'; } /** * Modify the persister configuration, * or initialize a new one for this component. */ public function configurePersister(): void { // customize the persister for this specific table $this->layoutPersister ->setKey('custom_key'. auth()->id()) ->setCacheDriver('redis') ->setExpiration(60 * 24 * 7 * 4); // or create a new persister for this specific table $this->layoutPersister = new CustomPersister($this); } } ``` -------------------------------- ### Enable Auto Mobile Layout Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Automatically apply the grid layout for mobile users if no previous layout preference is saved. This behavior can be enabled or disabled via the plugin configuration. ```php // Panel plugin TableLayoutTogglePlugin::make() ->enableAutoMobileLayout(); // pass false to disable explicitly // Standalone config 'auto_mobile_layout' => true, ``` -------------------------------- ### Apply HasToggleableTable Trait to Livewire Components Source: https://context7.com/hydrat-agency/filament-table-layout-toggle/llms.txt Apply the HasToggleableTable trait to Livewire components containing Filament tables to manage layout state, register persisters, and dispatch layout change events. ```php use Hydrat\TableLayoutToggle\Concerns\HasToggleableTable; use Filament\Resources\Pages\ListRecords; // In a Filament panel resource page: class ListUsers extends ListRecords { use HasToggleableTable; } // In a standalone Livewire table component: use Livewire\Component; use Filament\Tables\Contracts\HasTable; use Filament\Forms\Contracts\HasForms; class ListUsers extends Component implements HasForms, HasTable { use \Filament\Tables\Concerns\InteractsWithTable; use \Filament\Forms\Concerns\InteractsWithForms; use HasToggleableTable; // adds $layoutView, isGridLayout(), isListLayout(), etc. } ``` -------------------------------- ### Include Layout Persister View Asset Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Add the `renderLayoutViewPersister()` to your Blade view to enable persisting the table layout in local storage. This should be placed after the table rendering. ```blade [...] {{ $this->table }} {{ $this->renderLayoutViewPersister() }} <-- Add this line ``` -------------------------------- ### Add HasToggleableTable Trait to Livewire Component Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Include the `HasToggleableTable` trait in your Livewire component to enable table layout toggling. Ensure your component implements `HasForms`, `HasTable`, and `HasActions`. ```php namespace App\Livewire\Users; use Hydrat\TableLayoutToggle\Concerns\HasToggleableTable; class ListUsers extends Component implements HasForms, HasTable, HasActions { use InteractsWithTable; use InteractsWithActions; use InteractsWithForms; use HasToggleableTable; // <-- Add this line } ``` -------------------------------- ### Use HasToggleableTable Trait in Filament Component Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Apply the `HasToggleableTable` trait to your Filament component (e.g., `ListRecords`) to enable table layout toggling functionality. ```php use Hydrat\TableLayoutToggle\Concerns\HasToggleableTable; class MyListRecords extends ListRecords { use HasToggleableTable; } ``` -------------------------------- ### Disable Default Toggle Action Source: https://github.com/hydrat-agency/filament-table-layout-toggle/blob/main/README.md Disable the default toggle action provided by the plugin during plugin registration if you intend to use your own custom action. ```php $panel ->plugins([ TableLayoutTogglePlugin::make() ->displayToggleAction(false), ]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.