### Complete Full Page Livewire Table Component Example in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/usage/creating-components.md This comprehensive example illustrates a `DataTableComponent` configured for full-page usage, combining `setPrimaryKey()`, `setLayout()`, and `setSlot()` methods within the `configure()` method. It provides a complete setup for a Livewire Table that integrates with a custom layout and slot. ```php setPrimaryKey('id') ->setLayout('path-to-layout') ->setSlot('slot-name-here'); } public function columns(): array { return [ Column::make('ID', 'id') ->sortable(), Column::make('Name') ->sortable(), ]; } } ``` -------------------------------- ### Installing Laravel Livewire Tables via Composer Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/recommended.md Installs the `rappasoft/laravel-livewire-tables` package using Composer, adding it to your project's dependencies. ```Shell composer require rappasoft/laravel-livewire-tables ``` -------------------------------- ### Installing Laravel Livewire Tables (Bash) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/README.md This command installs the `rappasoft/laravel-livewire-tables` package using Composer. It's the essential first step to integrate the dynamic table component into a Laravel project, making its functionalities available for use. ```bash composer require rappasoft/laravel-livewire-tables ``` -------------------------------- ### Installing Laravel Livewire Tables via Composer Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/installation.md This command installs the `rappasoft/laravel-livewire-tables` package into your Laravel project using Composer. Composer is a dependency manager for PHP, and this command fetches the package from Packagist and adds it to your project's `composer.json` and `composer.lock` files, making its functionalities available for use. ```bash composer require rappasoft/laravel-livewire-tables ``` -------------------------------- ### Building Base Query for Livewire Table (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This `builder` method defines the base Eloquent query for the Livewire table. It starts with `User::query()` and conditionally applies `where` clauses for 'name' and 'email' based on `columnSearch` values, allowing for dynamic search functionality. ```PHP public function builder(): Builder { return User::query() ->when($this->columnSearch['name'] ?? null, fn ($query, $name) => $query->where('users.name', 'like', '%' . $name . '%')) ->when($this->columnSearch['email'] ?? null, fn ($query, $email) => $query->where('users.email', 'like', '%' . $email . '%')); } ``` -------------------------------- ### Running Package Tests (Bash) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/README.md This command executes the automated test suite for the `rappasoft/laravel-livewire-tables` package. It's used to verify the package's functionality and ensure all features are working correctly after installation or any modifications. ```bash composer test ``` -------------------------------- ### Defining HasMany Relationship in User Model (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/misc/one-of-many-example.md This snippet defines a `hasMany` relationship named `things` on the `User` model, linking a user to multiple `Things` records. It is a standard Eloquent relationship setup, crucial for accessing related data. ```php public function things(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Things::class); } ``` -------------------------------- ### Implementing Activate Bulk Action (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This `activate` method implements the 'activate' bulk action. It updates the 'active' status to `true` for all selected users and then clears the selection. ```PHP public function activate() { User::whereIn('id', $this->getSelected())->update(['active' => true]); $this->clearSelected(); } ``` -------------------------------- ### Example Blade Template for Filter Pills Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filters/filter-pills.md This Blade example demonstrates how to use the provided `$filterKey` and `$filterPillData` properties to display customized filter values within the filter pills area, leveraging the `x-livewire-tables::tools.filter-pills.wrapper` component. ```blade @aware(['tableName','isTailwind','isBootstrap','isBootstrap4','isBootstrap5']) @props(['filterKey', 'filterPillData']) getFilterPillDisplayData() }}> ``` -------------------------------- ### Creating a Bare Bones Livewire Table Component in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/usage/creating-components.md This snippet illustrates the fundamental structure of a Livewire Table component. It extends `Rappasoft\LaravelLivewireTables\DataTableComponent` and defines the model, primary key configuration, and the columns to be displayed, serving as the minimal setup for a functional table. ```php setPrimaryKey('id'); } public function columns(): array { return [ Column::make('ID', 'id') ->sortable(), Column::make('Name') ->sortable(), ]; } } ``` -------------------------------- ### Starting Reordering in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/reordering/available-methods.md This is a shorthand method to start reordering for the component, equivalent to `setCurrentlyReorderingStatus(true)`. While typically handled by a reorder button, this method allows programmatic initiation. ```PHP public function configure(): void { // Shorthand for $this->setCurrentlyReorderingStatus(true); $this->setCurrentlyReorderingEnabled(); } ``` -------------------------------- ### Defining Bulk Actions for Livewire Table (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This `bulkActions` method defines the available bulk actions for the Livewire table. It returns an associative array mapping action keys ('activate', 'deactivate') to their display names. ```PHP public function bulkActions(): array { return [ 'activate' => 'Activate', 'deactivate' => 'Deactivate', ]; } ``` -------------------------------- ### Defining a Basic User Table Component in Laravel Livewire (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/basic-example.md This PHP snippet defines a `UsersTable` Livewire component extending `DataTableComponent`. It specifies the `User` model, configures 'id' as the primary key, and defines 'Name', 'E-mail', and 'Address' columns, making them sortable and searchable. The 'Address' column also collapses on tablet devices for better responsiveness. ```php setPrimaryKey('id'); } public function columns(): array { return [ Column::make('Name') ->sortable() ->searchable(), Column::make('E-mail', 'email') ->sortable() ->searchable(), Column::make('Address', 'address.address') ->sortable() ->searchable() ->collapseOnTablet(), ]; } } ``` -------------------------------- ### Conditional Icon and Attribute Application Example in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/column-types/icon_column.md This example demonstrates a more complex conditional logic for applying both icons and attributes. It uses `setIcon` to choose an icon based on status (check for 1, x for others) and `attributes` to apply different classes and stroke colors based on status values 3, 2, or any other. This showcases how to handle multiple conditions for visual customization. ```PHP IconColumn::make('Icon', 'status') ->setIcon(function ($row, $value) { if($value == 1) { return "heroicon-o-check-circle"; } else { return "heroicon-o-x-circle"; } }) ->attributes(function ($row, $value) { if($value == 3) { return [ 'class' => 'w-3 h-3', 'stroke' => '#008000' ]; } else if($value == 2) { return [ 'class' => 'w-3 h-3', 'stroke' => '#0000FF' ]; } else { return [ 'class' => 'w-3 h-3', 'stroke' => '#FF0000' ]; } }), ``` -------------------------------- ### Enabling Basic Column Searching in Laravel Livewire Tables Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/columns/available-methods.md This example shows how to enable basic search functionality for a specific column. By chaining the `searchable` method onto the `Column::make()` definition, the column's content will be included in the table's search queries. ```PHP Column::make('Name') ->searchable(), ``` -------------------------------- ### Using Registered Livewire Component from Non-Standard Location - HTML Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/rendering.md This HTML snippet shows how to render a Livewire component that has been registered via a service provider (as shown in the preceding PHP example). The component is referenced by the alias defined during registration, allowing it to be used despite its non-standard file path. ```HTML ``` -------------------------------- ### Bootstrap 4 Column Search Input (Blade HTML) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This Blade snippet renders a search input field for table columns when the Livewire Tables theme is set to 'bootstrap-4'. It uses `wire:model.debounce` for real-time search and is styled with Bootstrap classes. ```HTML @if (config('livewire-tables.theme') === 'bootstrap-4')
null, 'email' => null, ]; public function configure(): void { $this->setPrimaryKey('id') ->setReorderEnabled() ->setSingleSortingDisabled() ->setHideReorderColumnUnlessReorderingEnabled() ->setFilterLayoutSlideDown() ->setRememberColumnSelectionDisabled() ->setSecondaryHeaderTrAttributes(function($rows) { return ['class' => 'bg-gray-100']; }) ->setSecondaryHeaderTdAttributes(function(Column $column, $rows) { if ($column->isField('id')) { return ['class' => 'text-red-500']; } return ['default' => true]; }) ->setFooterTrAttributes(function($rows) { return ['class' => 'bg-gray-100']; }) ->setFooterTdAttributes(function(Column $column, $rows) { if ($column->isField('name')) { return ['class' => 'text-green-500']; } return ['default' => true]; }) ->setUseHeaderAsFooterEnabled() ->setHideBulkActionsWhenEmptyEnabled(); } public function columns(): array { return [ ImageColumn::make('Avatar') ->location(function($row) { return asset('img/logo-'.$row->id.'.png'); }) ->attributes(function($row) { return [ 'class' => 'w-8 h-8 rounded-full', ]; }), Column::make('Order', 'sort') ->sortable() ->collapseOnMobile() ->excludeFromColumnSelect(), Column::make('ID', 'id') ->sortable() ->setSortingPillTitle('Key') ->setSortingPillDirections('0-9', '9-0') ->secondaryHeader(function($rows) { return $rows->sum('id'); }) ->html(), Column::make('Name') ->sortable() ->searchable() ->view('tables.cells.actions') ->secondaryHeader(function() { return view('tables.cells.input-search', ['field' => 'name', 'columnSearch' => $this->columnSearch]); }) ->html(), Column::make('E-mail', 'email') ->sortable() ->searchable() ->secondaryHeader(function() { return view('tables.cells.input-search', ['field' => 'email', 'columnSearch' => $this->columnSearch]); }), Column::make('Address', 'address.address') ->sortable() ->searchable() ->collapseOnTablet(), Column::make('Address Group', 'address.group.name') ->sortable() ->searchable() ->collapseOnTablet(), Column::make('Group City', 'address.group.city.name') ->sortable() ->searchable() ->collapseOnTablet(), BooleanColumn::make('Active') ->sortable() ->collapseOnMobile(), Column::make('Verified', 'email_verified_at') ->sortable() ->collapseOnTablet(), Column::make('Tags') ->label(fn($row) => $row->tags->pluck('name')->implode(', ')) ]; } public function filters(): array { return [ MultiSelectFilter::make('Tags') ->options( Tag::query() ->orderBy('name') ->get() ->keyBy('id') ->map(fn($tag) => $tag->name) ->toArray() )->filter(function(Builder $builder, array $values) { $builder->whereHas('tags', fn($query) => $query->whereIn('tags.id', $values)); }) ->setFilterPillValues([ '3' => 'Tag 1', ]), SelectFilter::make('E-mail Verified', 'email_verified_at') ->setFilterPillTitle('Verified') ->options([ ``` -------------------------------- ### Implementing Deactivate Bulk Action (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This `deactivate` method implements the 'deactivate' bulk action. It updates the 'active' status to `false` for all selected users and then clears the selection. ```PHP public function deactivate() { User::whereIn('id', $this->getSelected())->update(['active' => false]); $this->clearSelected(); } ``` -------------------------------- ### Example Custom Filter Label Blade Template - Blade/PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filters/available-filter-methods.md This example Blade template illustrates how to construct a custom filter label. It uses `@aware` and `@props` to access properties passed from the filter instance, such as `$filter`, `$filterLayout`, and `$tableName`, and applies conditional styling based on the theme (Tailwind or Bootstrap) and layout type (popover or slide-down). ```Blade @aware([ 'tableName']) @props(['filter', 'filterLayout' => 'popover', 'tableName' => 'table', 'isTailwind' => false, 'isBootstrap' => false, 'isBootstrap4' => false, 'isBootstrap5' => false, 'for' => null]) ``` -------------------------------- ### Setting Livewire Table Loading Placeholder Status (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/datatable/loaders.md This PHP example shows how to explicitly set the status of the loading placeholder for a `Laravel-Livewire-Tables` component. The `setLoadingPlaceholderStatus(true)` method enables the placeholder, controlling its visibility based on the loading state. ```PHP public function configure(): void { $this->setLoadingPlaceholderStatus(true); } ``` -------------------------------- ### Configuring BooleanFilter with Default Values and Pill Labels in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filter-types/filters-boolean.md This example extends the `BooleanFilter` usage by demonstrating how to set default filter values and customize the display text for filter pills. The `setFilterPillValues` method maps boolean states to user-friendly labels, while `setFilterDefaultValue` pre-selects the filter's initial state, enhancing user experience and clarity. ```PHP BooleanFilter::make('Limit to Older Enabled Users') ->filter(function (Builder $builder, bool $enabled) { if ($enabled) { $builder->where('status',true)->where('age', '>', 60); } }) ->setFilterPillValues([ true => 'Active', false => 'Inactive', ]) ->setFilterDefaultValue(true) ``` -------------------------------- ### Tailwind Column Search Input (Blade HTML) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This Blade snippet renders a search input field for table columns when the Livewire Tables theme is set to 'tailwind'. It uses `wire:model.debounce` for real-time search and includes a clear button for the search input, styled with Tailwind CSS classes. ```HTML @if (config('livewire-tables.theme') === 'tailwind')
@if (isset($columnSearch[$field]) && strlen($columnSearch[$field])) @endif
@endif ``` -------------------------------- ### Formatting Date Columns with Input and Output Formats (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/column-types/date_columns.md This example shows how to configure a date column when the input is a string, allowing both an `inputFormat` ('Y-m-d H:i:s') and an `outputFormat` ('Y-m-d') to be specified. This is useful for converting string dates from the database into a desired display format. ```php DateColumn::make('Last Charged', 'last_charged_at') ->inputFormat('Y-m-d H:i:s') ->outputFormat('Y-m-d'), ``` -------------------------------- ### Customizing TextFilter Input Attributes - PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filters/available-filter-methods.md This example illustrates how to use `setInputAttributes` to customize the input field for a `TextFilter`. It demonstrates setting `maxlength`, `placeholder`, custom CSS classes, and controlling whether default colors and styling are retained or replaced. ```PHP public function filters(): array { return [ TextFilter::make('Name') ->setInputAttributes([ 'maxlength' => '75', 'placeholder' => 'Enter a Name', 'class' => 'text-white bg-red-500 dark:bg-red-500', 'default-colors' => false, 'default-styling' => true, ]), ]; } ``` -------------------------------- ### Basic User Data Table Component (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/README.md This PHP class, `UsersTable`, extends `DataTableComponent` to create a basic Livewire data table. It configures the primary key to 'id' and defines two columns, 'ID' and 'Name', for displaying user data from the `App\Domains\Auth\Models\User` model. This serves as a foundational example for building custom data tables. ```php setPrimaryKey('id'); } public function columns(): array { return [ Column::make('ID', 'id') ->sortable(), Column::make('Name') ->sortable(), ]; } } ``` -------------------------------- ### Defining Livewire Table Filters (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This PHP snippet defines an array of filters for a Laravel Livewire Table. It includes `SelectFilter` for email verification status, user active status, and address groups, as well as `DateFilter` for email verification date ranges. Each filter applies specific `where` clauses to the Eloquent query builder. ```PHP '' => 'Any', 'yes' => 'Yes', 'no' => 'No', ]) ->filter(function(Builder $builder, string $value) { if ($value === 'yes') { $builder->whereNotNull('email_verified_at'); } elseif ($value === 'no') { $builder->whereNull('email_verified_at'); } }), SelectFilter::make('Active') ->setFilterPillTitle('User Status') ->setFilterPillValues([ '1' => 'Active', '0' => 'Inactive', ]) ->options([ '' => 'All', '1' => 'Yes', '0' => 'No', ]) ->filter(function(Builder $builder, string $value) { if ($value === '1') { $builder->where('active', true); } elseif ($value === '0') { $builder->where('active', false); } }), SelectFilter::make('Address Group') ->options([ '' => 'All', AddressGroup::query() ->orderBy('type') ->get() ->groupBy('type') ->map(fn ($addressGroup) => $addressGroup->pluck('type', 'id')->filter()) ->toArray(), ]) ->filter(function(Builder $builder, string $value) { $builder->where('address_groups.type', $value); }), DateFilter::make('Verified From') ->config([ 'min' => '2020-01-01', 'max' => '2021-12-31', ]) ->filter(function(Builder $builder, string $value) { $builder->where('email_verified_at', '>=', $value); }), DateFilter::make('Verified To') ->filter(function(Builder $builder, string $value) { $builder->where('email_verified_at', '<=', $value); }), ]; ``` -------------------------------- ### Rendering Multiple Same Livewire Table Components with Different Parameters (Non-Working Example) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/misc/multiple-tables.md This HTML snippet illustrates a common pitfall: rendering the same Livewire table component multiple times on the same page, even with different parameters. This approach typically leads to state conflicts because both instances attempt to use the same query string parameters, causing unexpected behavior. ```HTML ``` -------------------------------- ### Rendering Multiple Different Livewire Table Components (Working Example) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/misc/multiple-tables.md This HTML snippet demonstrates the correct way to render multiple distinct Livewire table components on the same page. Each component (e.g., 'users-table' and 'roles-table') operates independently, managing its own state without conflicts. ```HTML ``` -------------------------------- ### Applying Attributes to Livewire Table Loading Placeholder (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/datatable/loaders.md This PHP example demonstrates how to apply custom HTML attributes to the main container of the loading placeholder in a `Laravel-Livewire-Tables` component. The `setLoadingPlaceHolderAttributes([])` method accepts an associative array of attribute key-value pairs. ```PHP public function configure(): void { $this->setLoadingPlaceHolderAttributes([]); } ``` -------------------------------- ### Implementing Table Row Reordering (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This `reorder` method handles updating the sort order of table rows. It iterates through the provided items, finds each user by its primary key, and updates their 'sort' column based on the new order. ```PHP public function reorder($items): void { foreach ($items as $item) { User::find($item[$this->getPrimaryKey()])->update(['sort' => (int)$item[$this->getDefaultReorderColumn()]]); } } ``` -------------------------------- ### Rendering Column Cell with a View (Shorthand) in Laravel Livewire Tables Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/columns/available-methods.md This example provides a shorthand method for rendering a Blade view directly within a column cell. Instead of using `format` to return a view, you can simply chain the `view('view.name')` method to achieve the same result. ```PHP Column::make('Name') ->view('my.custom.view'), ``` -------------------------------- ### Applying Attributes to Livewire Table Loading Placeholder Wrapper (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/datatable/loaders.md This PHP example shows how to apply custom HTML attributes to the wrapper element surrounding the loading placeholder in a `Laravel-Livewire-Tables` component. The `setLoadingPlaceHolderWrapperAttributes([])` method enables styling or scripting the wrapper container. ```PHP public function configure(): void { $this->setLoadingPlaceHolderWrapperAttributes([]); } ``` -------------------------------- ### Passing Parameters to Configurable Areas in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/datatable/configurable-areas.md This example demonstrates how to pass dynamic parameters from your Livewire component's `mount` method or other services to a configurable area's view. Parameters are provided as an array within the `setConfigurableAreas` method, allowing the view to access component data or resolved service instances. ```PHP public function configure(): void { $this->setConfigurableAreas([ 'toolbar-left-start' => [ 'path.to.my.view', [ 'param1' => $this->user_id, 'param2' => resolve(MyService::class)->getThing($this->user_id) ] ] ]); } ``` -------------------------------- ### Rendering HTML for Custom Column Labels in Laravel Livewire Tables Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/columns/available-methods.md This example demonstrates how to return raw HTML content for a custom column label. By using the `label` method with a closure that returns an HTML string and then chaining the `html()` method, the label will be rendered as HTML. ```PHP Column::make('My one off column') ->label( fn($row, Column $column) => ''.$row->this_other_column.'' ) ->html(), ``` -------------------------------- ### Rendering HTML for LinkColumn in Laravel Livewire Tables Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/columns/available-methods.md This example shows how to render HTML content for a `LinkColumn` type. Similar to regular columns, chaining the `html()` method after defining the title and location allows the link's content to be rendered as raw HTML. ```PHP LinkColumn::make('Name', 'name') ->title(fn ($row) => 'Title') ->location(fn ($row) => "#$row->id") ->html(), ``` -------------------------------- ### Setting Default DateRangeFilter Value with minDate/maxDate Keys (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filter-types/filters-daterange.md Shows how to set a default date range value for the `DateRangeFilter` using the `setFilterDefaultValue` method. This specific example uses an associative array with `minDate` and `maxDate` keys to define the start and end dates, which will be applied when the table first loads. ```PHP DateRangeFilter::make('EMail Verified Range') ->setFilterDefaultValue(['minDate' => '2024-05-05', 'maxDate' => '2024-06-06']) ``` -------------------------------- ### Running Frontend Build Process (NPM) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/recommended.md Executes the `npm run build` command, which compiles and bundles frontend assets, including the Livewire Tables assets imported earlier, for production deployment. ```Shell npm run build ``` -------------------------------- ### Setting Default DateRangeFilter Value with Indexed Array (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filter-types/filters-daterange.md Presents another method for setting a default date range for the `DateRangeFilter` using `setFilterDefaultValue`. This example uses a simple indexed array where the first element is the start date and the second is the end date, offering a concise way to define defaults. ```PHP DateRangeFilter::make('EMail Verified Range') ->setFilterDefaultValue(['2024-05-05', '2024-06-06']) ``` -------------------------------- ### Implementing the configure Method in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/usage/configuration.md This snippet shows the basic implementation of the `configure` method, which is required for Laravel Livewire Tables components. It serves as the entry point for all table configurations. ```PHP public function configure(): void {} ``` -------------------------------- ### Configuring Tailwind CSS Content Path for Laravel Livewire Tables (JavaScript) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/upgrade-guide.md This JavaScript snippet shows how to include the Laravel Livewire Tables package's view path in the `content` array of your Tailwind CSS configuration. This is essential for production builds to ensure Tailwind scans and includes all necessary utility classes from the package's Blade views, preventing missing styles. It's also advised to add your `app/Livewire/**/*.php` path. ```JavaScript content: [ './vendor/rappasoft/laravel-livewire-tables/resources/views/**/*.blade.php', ]; ``` -------------------------------- ### Querying User with Latest Thing Relationship in Livewire Table Builder (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/misc/one-of-many-example.md This `builder` method for a Livewire Table constructs the base query. It eager loads the `things` relationship, selecting only `id`, `user_id`, and `name`, ordering by `created_at` in descending order, and limiting to one record to fetch only the most recent 'Thing' for each user, preventing duplicates in the 'OneOfMany' scenario. ```php public function builder(): Builder { return User::query()->with(['things' => function ($query) { $query->select(['id','user_id','name'])->orderBy('created_at', 'desc')->limit(1); }]); } ``` -------------------------------- ### Publishing Livewire Tables Configuration Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/recommended.md Publishes the default configuration file for Laravel Livewire Tables to `config/livewire-tables.php`, allowing for custom settings. ```Shell php artisan vendor:publish --tag="livewire-tables-config" ``` -------------------------------- ### Displaying Latest Related Thing in Livewire Table Column (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/misc/one-of-many-example.md This `Column` definition for a Livewire Table displays the name of the most recently created 'Thing' associated with the current row's user. It accesses the `things` relationship and retrieves the `name` of the first (most recent) related record, assuming the relationship is eager loaded and ordered correctly. ```php Column::make('Latest Thing') ->label( fn ($row, Column $column) => $row->things->first()->name ), ``` -------------------------------- ### Publishing Laravel Livewire Tables Assets (Bash) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/configuration.md These Bash commands publish various assets (config, views, translations, public files) for the 'rappasoft/laravel-livewire-tables' package, allowing customization. Publishing views is generally not recommended unless specific changes are required due to frequent updates. ```bash php artisan vendor:publish --provider="Rappasoft\LaravelLivewireTables\LaravelLivewireTablesServiceProvider" --tag=livewire-tables-config php artisan vendor:publish --provider="Rappasoft\LaravelLivewireTables\LaravelLivewireTablesServiceProvider" --tag=livewire-tables-views php artisan vendor:publish --provider="Rappasoft\LaravelLivewireTables\LaravelLivewireTablesServiceProvider" --tag=livewire-tables-translations php artisan vendor:publish --provider="Rappasoft\LaravelLivewireTables\LaravelLivewireTablesServiceProvider" --tag=livewire-tables-public ``` -------------------------------- ### Importing Livewire Tables Assets for Bundling (JavaScript) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/recommended.md Adds an import statement to `resources/js/app.js` to include all Livewire Tables frontend assets, enabling them to be bundled by your JavaScript build process instead of being automatically injected. ```JavaScript import '../../vendor/rappasoft/laravel-livewire-tables/resources/imports/laravel-livewire-tables-all.js'; ``` -------------------------------- ### Configuring DateTime Filter Options in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filter-types/filters-datetime.md This example shows how to configure a DateTime filter with various options using the `config()` method. It allows setting `min` and `max` dates for validation, defining `pillFormat` for how the filter's value appears in filter pills, and providing a `placeholder` text for the input field. ```php public function filters(): array { return [ DateTimeFilter::make('Verified From') ->config([ 'min' => '2022-11-31 00:00:00', // Earliest Acceptable DateTime 'max' => '2022-12-31 05:00:00', // Latest Acceptable Date 'pillFormat' => 'd M Y - H:i', // Format for use in Filter Pills 'placeholder' => 'Enter Date Time', // A placeholder value ]) ]; } ``` -------------------------------- ### Creating a WireLinkColumn With Confirmation Message in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/column-types/wire_link_column.md This example shows how to add a confirmation message to a `WireLinkColumn` using Livewire 3's `wire:confirm` approach. The `confirmMessage` method displays a modal before executing the specified Livewire action, enhancing user experience for critical operations. It also applies custom CSS classes to the button. ```php WireLinkColumn::make("Delete Item") ->title(fn($row) => 'Delete Item') ->confirmMessage('Are you sure you want to delete this item?') ->action(fn($row) => 'delete("'.$row->id.'")') ->attributes(fn($row) => [ 'class' => 'btn btn-danger', ]), ``` -------------------------------- ### Using a Filter as a Column Footer (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/columns/footer.md This example illustrates how to repurpose an existing filter as a column footer in Laravel Livewire Tables. It shows two methods: directly passing a `SelectFilter` instance (which can be hidden from menus) or using the `footerFilter()` shorthand method with the filter's key. This allows for displaying filter-related information or controls within the table's footer. ```PHP // Example filter SelectFilter::make('Active') ->hiddenFromAll(), // Optional, hides the filter from the menus, pills, count. // You can pass a filter directly Column::make('Active') ->footer($this->getFilterByKey('active')), // Or use the shorthand method Column::make('Active') ->footerFilter('active'), // Takes the key from the filter, which you can find in the query string when the filter is applied. ``` -------------------------------- ### Defining Bulk Actions via Configure Method (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/bulk-actions/creating-bulk-actions.md This snippet shows how to define bulk actions using the `setBulkActions` method within the component's `configure` method. This is the most flexible approach, often used for setting up component-wide configurations. It allows for programmatic definition of bulk actions, similar to the method approach, but within the lifecycle of component configuration. ```PHP public function configure(): void { $this->setBulkActions([ 'exportSelected' => 'Export', ]); } ``` -------------------------------- ### Setting Column Deselected by Default in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/columns/column-selection.md This example shows how to include a column in the column select menu but have it deselected by default when the table loads, allowing users to manually enable it. ```php Column::make('Address', 'address.address') ->deselected(), ``` -------------------------------- ### Conditionally Selecting Columns with Boolean in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/columns/column-selection.md This example demonstrates how to select a column based on a direct boolean expression, such as the user's authentication status, making it selected if the condition is true. ```php Column::make('Address', 'address.address') ->selectedIf(Auth::user()), ``` -------------------------------- ### Conditionally Deselecting Columns with Boolean in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/columns/column-selection.md This example demonstrates how to deselect a column based on a direct boolean expression, such as the user's authentication status, making it deselected if the condition is true. ```php Column::make('Address', 'address.address') ->deselectedIf(!Auth::user()), ``` -------------------------------- ### Configuring Laravel Livewire Tables Frontend Theme (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/configuration.md This PHP snippet shows the content of the published 'livewire-tables.php' configuration file, specifically demonstrating how to set the frontend theme (e.g., 'tailwind', 'bootstrap-4', 'bootstrap-5') for the Laravel Livewire Tables package. ```php 'tailwind', ]; ``` -------------------------------- ### Hiding a Specific Sales Table on Load in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/misc/hiding-the-table.md This example shows how to hide a specific `SalesTable` component by default. The `tableName` property is set to 'sales' for identification, and `setShouldBeHidden()` is invoked in the `mount()` method to ensure the table is hidden when the component is initialized. This is useful for tables that should only appear based on user interaction or specific conditions. ```php class SalesTable extends DataTableComponent { public string $tableName = 'sales'; // Required to keep the call specific public function mount() { $this->setShouldBeHidden(); // Defaults the table to be hidden, note that this is in MOUNT and not CONFIGURE } // Configure/Columns/Filters etc } ``` -------------------------------- ### Configuring Tailwind CSS to Scan Livewire Tables Views (JavaScript) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/recommended.md Updates `tailwind.config.js` by adding paths to Livewire Tables' vendor view files to the `content` section, ensuring Tailwind CSS correctly scans and includes all necessary utility classes from the package. ```JavaScript './vendor/rappasoft/laravel-livewire-tables/resources/views/*.blade.php', './vendor/rappasoft/laravel-livewire-tables/resources/views/**/*.blade.php', ``` -------------------------------- ### Setting Filter Layout in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filters/available-component-methods.md This method allows setting the overall layout for the filters within the component. It accepts a string parameter, for example, `'slide-down'`, to define the desired layout style. ```PHP public function configure(): void { $this->setFilterLayout('slide-down'); } ``` -------------------------------- ### Recommended Approach for Multiple Similar Livewire Table Components Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/misc/multiple-tables.md This HTML snippet provides the recommended solution for scenarios where multiple conceptually similar tables are needed on the same page. Instead of reusing the same component, create distinct Livewire components (e.g., 'active-users-table', 'pending-users-table') to ensure independent state management and avoid conflicts. ```HTML ``` -------------------------------- ### Column Search Input and Clear Button (Bootstrap 5 Theme) - Blade Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/examples/advanced-example.md This Blade snippet renders a complete column search input field and a conditional clear button, specifically tailored for the 'bootstrap-5' theme. The input uses 'wire:model.debounce' for live search, and the button clears the search term for the '$field' using 'wire:click' when a value is present. ```Blade @if (config('livewire-tables.theme') === 'bootstrap-5')
@if (isset($columnSearch[$field]) && strlen($columnSearch[$field])) @endif
@endif ``` -------------------------------- ### Disabling Third-Party Asset Injection in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filter-types/filters-daterange.md This PHP configuration snippet disables the automatic injection of third-party assets by `laravel-livewire-tables`. This is recommended when Flatpickr assets are already bundled, loaded via CDN, or installed locally to prevent conflicts. ```php 'inject_third_party_assets_enabled' => false, ``` -------------------------------- ### Configuring Tailwind CSS to Scan Livewire Components (JavaScript) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/recommended.md Recommends adding paths to your application's Livewire components (e.g., `./app/Livewire/*.php`) to the Tailwind CSS `content` configuration, ensuring that classes used within methods like `setTdAttributes` are properly included in the final CSS bundle. ```JavaScript './app/Livewire/*.php', './app/Livewire/**/*.php', ``` -------------------------------- ### Setting Primary Key in Laravel Livewire Tables (PHP) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/usage/configuration.md This example demonstrates how to set the primary key for a Laravel Livewire Table component within the `configure` method. The primary key, such as 'id', is crucial for uniquely identifying rows in the table. ```PHP public function configure(): void { $this->setPrimaryKey('id'); } ``` -------------------------------- ### Configuring Bulk Action Confirmations in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/bulk-actions/available-methods.md Specifies which bulk actions should trigger a default `wire:confirm` pop-up before execution. The default message for these confirmations is 'Are you sure?'. This method is suitable when the default message is sufficient for the listed actions. ```PHP public function configure(): void { $this->setBulkActionConfirms([ 'delete', 'reset' ]); } ``` -------------------------------- ### Setting Table Head Attributes with Defaults in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/datatable/styling.md This example demonstrates how to add custom classes to the `` element while preserving its default classes. By setting the 'default' flag to `true` within `setTheadAttributes`, the new classes are appended to the existing ones. ```PHP public function configure(): void { $this->setTheadAttributes([ 'default' => true, 'class' => 'added these classes', ]); } ``` -------------------------------- ### Bundling Flatpickr Locales in JavaScript Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/filter-types/filters-daterange.md This JavaScript snippet demonstrates how to import specific Flatpickr locale files into your application's build pipeline. This approach requires `flatpickr` to be installed via npm and allows for selective inclusion of required languages. ```javascript import { Arabic } from "../imports/flatpickr/l10n/ar.js"; import { Catalan } from "../imports/flatpickr/l10n/cat.js"; import { Danish } from "../imports/flatpickr/l10n/da.js"; import { German } from "../imports/flatpickr/l10n/de.js"; import { Spanish } from "../imports/flatpickr/l10n/es.js"; import { French } from "../imports/flatpickr/l10n/fr.js"; import { Indonesian } from "../imports/flatpickr/l10n/id.js"; import { Italian } from "../imports/flatpickr/l10n/it.js"; import { Malaysian } from "../imports/flatpickr/l10n/ms.js"; import { Dutch } from "../imports/flatpickr/l10n/nl.js"; import { Portuguese } from "../imports/flatpickr/l10n/pt.js"; import { Russian } from "../imports/flatpickr/l10n/ru.js"; import { Thai } from "../imports/flatpickr/l10n/th.js"; import { Turkish } from "../imports/flatpickr/l10n/tr.js"; import { Ukrainian } from "../imports/flatpickr/l10n/uk.js"; ``` -------------------------------- ### Prompting for Missing Datatable Inputs (PHP Artisan) Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/start/commands.md Executing the `make:datatable` command without any arguments will trigger an interactive prompt. This allows the user to provide the necessary component name and model details step-by-step, which is useful when the exact arguments are not immediately known. ```bash php artisan make:datatable ``` -------------------------------- ### Configuring Bulk Actions in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/bulk-actions/available-methods.md Sets the available bulk actions for the component. This method expects an associative array where keys are action names and values are their display labels, defining the operations users can perform in bulk. ```PHP public function configure(): void { $this->setBulkActions([ 'exportSelected' => 'Export', ]); } ``` -------------------------------- ### Setting Table Body Attributes with Defaults in PHP Source: https://github.com/rappasoft/laravel-livewire-tables/blob/master/docs/datatable/styling.md This example shows how to add custom classes to the `` element while retaining its default classes. Setting the 'default' flag to `true` within `setTbodyAttributes` ensures that the new classes are merged with the existing ones. ```PHP public function configure(): void { $this->setTbodyAttributes([ 'default' => true, 'class' => 'added these classes', ]); } ```