Beartropy Tables
Creating a Table
Use the Artisan command to scaffold a new table component.
The Artisan Way
The make:btable command generates a new table class that extends YATBaseTable.
1php artisan make:btable MyBrandNewTable2 3# Or pre-fill columns from a model4php artisan make:btable MyBrandNewTable --model=User
Use the --model flag
--model=User will introspect the database schema and pre-fill the columns() method with matching column definitions. This saves time on large models.
Rendering the Table
Tables are Livewire components — render them like any other.
Full-Page Layout (Attribute)
For full-page components, add the #[Layout] attribute before the class:
1#[Layout('layouts.app')]2class MyBrandNewTable extends YATBaseTable
Full-Page Layout (Method)
Alternatively, set the layout inside the settings() method:
1public function settings(): void {2 $this->setLayout('layouts.app');3}
Embedded in a Blade View
To embed a table inside another view, use the standard Livewire tag:
1<livewire:mybrandnewtable />
Core Methods
Every table class relies on these key methods to define behavior.
Method Overview
settings(): void — Configure general behavior: title, column ID, bulk actions, state handler, layout, pagination, and more.
data(): array — Return the dataset as an array of associative arrays. Internally collected into a Collection. Not needed when using the $model property (Eloquent mode).
columns(): array — Define an array of Column instances with their modifiers (sorting, searching, styling, etc.).
filters(): array — Define an array of Filter instances for per-column filtering.
options(): array — Define custom dropdown actions that appear in the toolbar (e.g., export, bulk delete).
1public function settings(): void { 2 // Set general settings: title, column id, bulk, state handler, etc. 3} 4 5public function data(): array { 6 // Return array of data (not needed when using $model) 7} 8 9public function columns(): array {10 // Return array of Column instances11}12 13public function filters(): array {14 // Return array of Filter instances15}16 17public function options(): array {18 // Return array of custom options (dropdown actions)19}
Passing Data to the Table
Pass external data via Livewire public properties.
Public Properties
To pass data from a route or a parent view, declare public properties on your table component. They work exactly like any Livewire component property.
1<livewire:mytable color_type="primary">2 3class MyTable extends YATBaseTable4{5 public $color_type;6 ...7}
Complete Example
A minimal working table using Eloquent mode from the playground.
BasicUsersTable.php
This example shows a basic table backed by an Eloquent model. Define $model instead of data() to get automatic server-side pagination, searching, and sorting.
1use App\Models\User; 2use Beartropy\Tables\Classes\Columns\Column; 3use Beartropy\Tables\Classes\Columns\DateColumn; 4use Beartropy\Tables\YATBaseTable; 5 6class BasicUsersTable extends YATBaseTable 7{ 8 public $model = User::class; 9 10 public function columns(): array11 {12 return [13 Column::make('Name', 'name'),14 Column::make('Email', 'email'),15 DateColumn::make('Created', 'created_at')16 ->outputFormat('M d, Y'),17 ];18 }19 20 public function settings(): void21 {22 //23 }24}
Live Demo
Try it — sort, search, and interact with this table.
Basic Table
| # |
Name
|
Email
|
Created
|
|---|---|---|---|
| 1 | Alice Johnson | alice@example.com | Jan 15, 2025 |
| 2 | Bob Smith | bob@example.com | Feb 20, 2025 |
| 3 | Carol White | carol@example.com | Mar 10, 2025 |
| 4 | David Brown | david@example.com | Apr 05, 2025 |
| 5 | Eva Martinez | eva@example.com | May 22, 2025 |
| 6 | Frank Lee | frank@example.com | Jun 18, 2025 |
| 7 | Grace Kim | grace@example.com | Jul 03, 2025 |
| 8 | Henry Davis | henry@example.com | Aug 29, 2025 |
1<livewire:tables.demos.demo-basic-table />