PHP code example of accelade / grids

1. Go to this page and download the library: Download accelade/grids library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

accelade / grids example snippets


use Accelade\Grids\Grid;
use Accelade\Grids\Cards\Card;
use App\Models\Product;

$grid = Grid::make('products')
    ->query(Product::query())
    ->columns(3)
    ->card(
        Card::make()
            ->title(fn ($record) => $record->name)
            ->description(fn ($record) => $record->description)
            ->image(fn ($record) => $record->image_url)
            ->url(fn ($record) => route('products.show', $record))
    )
    ->fromRequest()
    ->paginate();

use Accelade\Grids\Grid;
use Accelade\Grids\Cards\Card;
use App\Models\Product;

$grid = Grid::make('products')
    ->query(Product::query())
    ->columns(4)
    ->gap('6')
    ->card(
        Card::make()
            ->title(fn ($record) => $record->name)
            ->description(fn ($record) => Str::limit($record->description, 100))
            ->image(fn ($record) => $record->image_url)
            ->url(fn ($record) => route('products.show', $record))
    );

use Accelade\Grids\Cards\Card;
use Accelade\Grids\Cards\CardSection;

Card::make()
    ->title(fn ($record) => $record->name)
    ->description(fn ($record) => $record->excerpt)
    ->sections([
        CardSection::make()
            ->label('Price')
            ->value(fn ($record) => '$' . number_format($record->price, 2))
            ->icon('heroicon-o-currency-dollar')
            ->color('success'),

        CardSection::make()
            ->label('Stock')
            ->value(fn ($record) => $record->stock . ' available')
            ->icon('heroicon-o-cube'),
    ]);

use Accelade\Grids\Cards\Card;
use Accelade\Actions\ViewAction;
use Accelade\Actions\EditAction;
use Accelade\Actions\DeleteAction;

Card::make()
    ->title(fn ($record) => $record->name)
    ->badge(fn ($record) => $record->is_featured ? 'Featured' : null, 'primary')
    ->actions([
        ViewAction::make(),
        EditAction::make(),
        DeleteAction::make(),
    ], position: 'footer');

// Fixed columns
$grid->columns(4);

// Responsive columns
$grid->columns([
    'default' => 1,
    'sm' => 2,
    'md' => 3,
    'lg' => 4,
    'xl' => 5,
]);

$grid = Grid::make('gallery')
    ->query(Photo::query())
    ->masonry()
    ->columns(4);

$grid = Grid::make('articles')
    ->query(Article::query())
    ->list(); // Single column list

$grid = Grid::make('products')
    ->heading('Product Gallery')
    ->description('Browse our collection')
    ->headerActions([
        CreateAction::make(),
        ExportAction::make(),
    ]);

$grid = Grid::make('products')
    ->emptyStateHeading('No products found')
    ->emptyStateDescription('Try adjusting your search or filters')
    ->emptyStateIcon('heroicon-o-cube')
    ->emptyStateActions([
        CreateAction::make()->label('Create Product'),
    ]);
bash
php artisan vendor:publish --tag=grids-config