0

Working with laravel 9 / filament": "^2.17.17 app I use RelationManager I want to show only some disabled fields(as Banner editor is rather big) , like :

and I want to set custom field with url to Banner editor (with target="_blank") from BannersRelationManager listing

Reading https://filamentphp.com/docs/2.x/forms/fields#building-custom-fields I create custom field with command :

php artisan make:form-field EditorItemLink

but I failed to pass id parameter from Bannerslisting , like :

class BannersRelationManager extends RelationManager
{
    protected static string $relationship = 'banners';

    protected static ?string $recordTitleAttribute = 'id';

    public static function form(Form $form): Form
    {
        [$locales] = Arr::divide(AppLocale::getAppLocaleSelectionItems(false));

        \Log::info(varDump($locales, ' -1 BannersRelationManager $locales::'));


        return $form
            ->schema(Card::make()->schema(
                [
                    Forms\Components\Placeholder::make('id')
                        ->content(fn (Banner $record): ?string => $record->id),
                    Forms\Components\Placeholder::make('creator')
                        ->content(fn (Banner $record): ?string => $record->creator->name),
                    Forms\Components\Placeholder::make('banner_clicked_counts_count')
                        ->content(fn (Banner $record): ?string => $record->banner_clicked_counts_count),
                    EditorItemLink::make('link_to_banner_editor')
                        ->itemLink(itemLink : 'admin/banners/NNN/edit') // In custom field I will replace NNN with id of any banner
                        ->itemId(itemId : fn (Banner $record): ?int => $record->id), // Error pointing at this line !
                ]

            ));
    }

in in custom field app/Forms/Components/EditorItemLink.php :

<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Field;

class EditorItemLink extends Field
{
    protected string $view = 'forms.components.editor-item-link';

    protected string $itemLink = '';
    protected ?int $itemId = null;

    public function itemLink(string $itemLink): static
    {
        $this->itemLink = $itemLink;

        return $this;
    }

    public function getItemLink(): string
    {
        return $this->itemLink;
    }


    public function itemId(string $itemId): static
    {
        $this->itemId = $itemId;

        return $this;
    }

    public function getItemId(): string
    {
        return $this->itemId;
    }

}

I got error :

App\Forms\Components\EditorItemLink::itemId(): Argument #1 ($itemId) must be of type string, Closure given, called in /app/Filament/Resources/BannerCategoryResource/RelationManagers/BannersRelationManager.php on line 51

In which way cab I pass id of any Banners listing ? Can it be done in some other way ? I searched in filament docs and did not find anything like I need ...

Thank you!

mstdmstd
  • 2,195
  • 17
  • 63
  • 140

0 Answers0