PHP code example of pojow / laravel-collection-table

1. Go to this page and download the library: Download pojow/laravel-collection-table 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/ */

    

pojow / laravel-collection-table example snippets


namespace App\Tables;

use App\Models\User;
use Pojow\LaravelCollectionTable\Abstracts\AbstractTableConfiguration;
use Pojow\LaravelCollectionTable\Column;
use Pojow\LaravelCollectionTable\Filters\SelectFilter;
use Pojow\LaravelCollectionTable\RowActions\DestroyRowAction;
use Pojow\LaravelCollectionTable\RowActions\EditRowAction;
use Pojow\LaravelCollectionTable\Table;

class UsersTable extends AbstractTableConfiguration
{
    protected function table(): Table
    {
        return Table::make()
            ->collection(User::all())
            ->filters([
                (new SelectFilter(__('Role'), 'role'))->options(['user', 'administrator']),
            ])
            ->rowActions([
                new EditRowAction('user.edit', 'id'),
                new DestroyRowAction('user.destroy', 'id'),
            ]);
    }

    protected function columns(): array
    {
        return [
            Column::make('username')
                ->searchable()
                ->sortable(),
            Column::make('first_name')
                ->searchable()
                ->sortable(),
            Column::make('last_name'),
            Column::make('email')
                ->searchable()
                ->sortable()
                ->format(fn (User $user) => "<a href='mailto:{$user->email}'>{$user->email}</a>", false),
        ];
    }
}