main

filamentphp/demo

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

ProductsRelationManager.php

TLDR

This file defines the ProductsRelationManager class, which extends the RelationManager class. It contains two methods: form() and table(). The form() method returns a form for the ProductResource, while the table() method returns a table for the ProductResource.

Classes

ProductsRelationManager

The ProductsRelationManager class extends the RelationManager class. It represents the relation manager for the "products" relationship. It provides two methods: form() and table().

Methods:

  • form(Form $form): Form: Returns a form for the ProductResource.
  • table(Table $table): Table: Returns a table for the ProductResource.
<?php

namespace App\Filament\Resources\Shop\CategoryResource\RelationManagers;

use App\Filament\Resources\Shop\ProductResource;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;

class ProductsRelationManager extends RelationManager
{
    protected static string $relationship = 'products';

    protected static ?string $recordTitleAttribute = 'name';

    public function form(Form $form): Form
    {
        return ProductResource::form($form);
    }

    public function table(Table $table): Table
    {
        return ProductResource::table($table)
            ->headerActions([
                Tables\Actions\CreateAction::make(),
            ])
            ->actions([
                Tables\Actions\DeleteAction::make(),
            ])
            ->groupedBulkActions([
                Tables\Actions\DeleteBulkAction::make(),
            ]);
    }
}