Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

KalimeroMK's avatar

Filament custom list Page

I'm working on a Filament project with a list page for "Habits," where each habit belongs to a specific category. Instead of listing all habits in a standard table format, I want to first display a grid of categories (each category as a col-3 box that includes the category name and image).

When a user clicks on a category box, I want to display a standard Filament list view that only shows the habits within that specific category.

What is the best approach to achieve this layout in Filament? Should I use custom widgets or a specific method to control the display? Any examples or guidance on implementing this design would be greatly appreciated!

0 likes
1 reply
LaryAI's avatar
Level 58

To achieve the desired layout in your Filament project, you can follow these steps:

  1. Create a Custom Page for Categories: First, you'll need to create a custom page in Filament to display the grid of categories. You can use Filament's page resource to create a custom page.

  2. Display Categories in a Grid: On this custom page, you can use a grid layout to display each category as a col-3 box. You can achieve this using Blade components or a custom view.

  3. Handle Category Clicks: When a user clicks on a category, you can redirect them to a standard Filament resource list view that is filtered by the selected category.

  4. Filter Habits by Category: In the Filament resource for habits, you can use query string filters to filter habits by the selected category.

Here's a basic implementation outline:

Step 1: Create a Custom Page for Categories

Create a new Filament page using the command:

php artisan make:filament-page CategoryGrid

Step 2: Implement the Category Grid

In the CategoryGrid page, you can use a Blade view to display the categories. Here's an example of how you might structure the Blade view:

<x-filament::page>
    <div class="grid grid-cols-3 gap-4">
        @foreach($categories as $category)
            <div class="col-span-1 border p-4">
                <img src="{{ $category->image_url }}" alt="{{ $category->name }}" class="w-full h-32 object-cover">
                <h3 class="text-lg font-bold mt-2">{{ $category->name }}</h3>
                <a href="{{ route('filament.resources.habits.index', ['category' => $category->id]) }}" class="text-blue-500">View Habits</a>
            </div>
        @endforeach
    </div>
</x-filament::page>

Step 3: Pass Categories to the View

In the CategoryGrid page class, pass the categories to the view:

use Filament\Pages\Page;
use App\Models\Category;

class CategoryGrid extends Page
{
    protected static string $view = 'filament.pages.category-grid';

    public function mount()
    {
        $this->categories = Category::all();
    }
}

Step 4: Filter Habits by Category

In your HabitResource, you can add a query string filter to filter habits by category:

use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use App\Models\Habit;

class HabitResource extends Resource
{
    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                // Define your columns here
            ])
            ->filters([
                Tables\Filters\SelectFilter::make('category')
                    ->options(Category::all()->pluck('name', 'id'))
                    ->query(function ($query, $value) {
                        return $query->where('category_id', $value);
                    }),
            ]);
    }
}

Step 5: Route Configuration

Ensure your routes are correctly set up to handle the redirection from the category grid to the filtered habits list.

By following these steps, you should be able to create a custom list page in Filament that displays categories in a grid and allows users to view habits filtered by category.

Please or to participate in this conversation.