Create a Grid

To create a grid, you need to extend the BaseLaraGrid class and implement the getColumns, and getDataSource methods.

use BoredProgrammers\LaraGrid\Components\ColumnComponents\Column;
use BoredProgrammers\LaraGrid\Livewire\BaseLaraGrid;
use Illuminate\Database\Eloquent\Builder;
use BoredProgrammers\LaraGrid\Filters\FilterResetButton;

class MyGrid extends BaseLaraGrid
{

    protected function getColumns(): array
    {
        return [
            Column::make('id', 'ID'),
            Column::make('name', 'Name'),
            // Add more columns as needed
        ];
    }

    protected function getDataSource(): Builder
    {
        return MyModel::query();
    }

}

In the getColumns method, you define the columns that will be displayed in the grid. The Column::make method takes two arguments: the model field and the label.

The getDataSource method should return an instance of Illuminate\Database\Eloquent\Builder for the model you want to display in the grid.

Last updated