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

renanjoppert's avatar

How can I make a Nested Resource in Filament V3 with Simple Resource Modules?

I trying to create an nested resources with filament v3. I have 3 modules: CourseResource > CourseModuleResource > LessonsResouce.

I see many tutorials, but all them are using complete resource, with list, create and edit pages. I want create with simple resource to use the modal actions.

0 likes
2 replies
LaryAI's avatar
Level 58

To create nested resources in Filament V3 using simple resource modules, you can follow these steps. This approach will allow you to manage CourseResource, CourseModuleResource, and LessonsResource in a nested manner, utilizing modal actions for a streamlined user experience.

Step 1: Define Your Resources

First, ensure that each of your resources (CourseResource, CourseModuleResource, LessonsResource) is set up correctly in Filament. Each resource should extend from Filament\Resources\Resource and define at least the basic schema needed for your application.

Step 2: Set Up Nested Resources

For nested resources, you need to define relationships in your resource classes. Here's how you can set up CourseResource to include CourseModuleResource:

namespace App\Filament\Resources;

use App\Filament\Resources\CourseModuleResource;
use App\Models\Course;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Forms;
use Filament\Tables;

class CourseResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('title')
                    ->required(),
                // Other fields...
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('title'),
                // Other columns...
            ])
            ->filters([
                //
            ]);
    }

    public static function getRelations(): array
    {
        return [
            CourseModuleResource::getRelation(),
        ];
    }

    public static function getModel(): string
    {
        return Course::class;
    }

    // Other methods...
}

Step 3: Define Relations in CourseModuleResource

Similarly, define the relation in CourseModuleResource to include LessonsResource:

namespace App\Filament\Resources;

use App\Filament\Resources\LessonsResource;
use App\Models\CourseModule;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Forms;
use Filament\Tables;

class CourseModuleResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->required(),
                // Other fields...
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('name'),
                // Other columns...
            ])
            ->filters([
                //
            ]);
    }

    public static function getRelations(): array
    {
        return [
            LessonsResource::getRelation(),
        ];
    }

    public static function getModel(): string
    {
        return CourseModule::class;
    }

    // Other methods...
}

Step 4: Implement Modal Actions

If you want to use modal actions (for creating or editing resources directly from modals), you can define actions in the actions method of your resource classes. Here's an example for CourseResource:

public static function actions(): array
{
    return [
        Tables\Actions\CreateAction::make(),
        Tables\Actions\EditAction::make(),
    ];
}

Conclusion

By setting up your resources as shown above, you can effectively manage nested resources in Filament V3. Each resource handles its own part of the application, and the nested structure is maintained through the relations defined in the resource classes. This setup also supports modal actions, making it convenient to create and edit nested resources without leaving the context of the current page.

Please or to participate in this conversation.