main

filamentphp/demo

Last updated at: 29/12/2023 09:43

ListPosts.php

TLDR

The ListPosts.php file is a part of the Blog\PostResource\Pages namespace in the Demo Projects project. It extends the ListRecords class and defines the ListPosts class. The class has a static property $resource that refers to the PostResource class. The class also overrides the getActions method to add a create action.

Classes

ListPosts

The ListPosts class extends the ListRecords class, which is a part of the Filament\Resources\Pages namespace. It represents a page that lists all the blog posts. The class has a static property $resource that refers to the PostResource class, which is used to provide the resource for the page. The class also overrides the getActions method to add a create action.

Methods

getActions()

The getActions method is overridden in the ListPosts class. It returns an array of actions that can be performed on the list of posts. Currently, it only includes the CreateAction action.

<?php

namespace App\Filament\Resources\Blog\PostResource\Pages;

use App\Filament\Resources\Blog\PostResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListPosts extends ListRecords
{
    protected static string $resource = PostResource::class;

    protected function getActions(): array
    {
        return [
            Actions\CreateAction::make(),
        ];
    }
}