Z3d0X / filament-fabricator

Block-Based Page Builder Skeleton for your Filament Apps
https://filamentphp.com/plugins/fabricator
MIT License
252 stars 48 forks source link

Undefined array key "data" #58

Closed kmaphane closed 1 year ago

kmaphane commented 1 year ago

Good day,

There is an issue with this package especially if you are dealing with data outside of the normal Fabricator process.

Let me explain:

I am building blocks as usual but some of the blocks just need data from a model. The documentation states you can do something like this:

return ['foo' => 'bar']

Sometimes it works, and sometimes it does not and returns the above error. I wish this could work.

This is a great package idea.

The block:

<?php

namespace App\Filament\Fabricator\PageBlocks\Support;

use App\Models\Support\Donor; use Filament\Forms\Components\Builder\Block; use Filament\Forms\Components\Placeholder; use Z3d0X\FilamentFabricator\PageBlocks\PageBlock;

class SupportDonors extends PageBlock { public static function getBlockSchema(): Block { return Block::make('support.support-donors') ->schema([ Placeholder::make('') ->content('Please manage under support management') ]); }

public static function mutateData(array $data): array
{
    $data = [
        'donors' => Donor::all()
    ];

    return $data;
}

}

The error:

ErrorException PHP 8.1.10 9.52.6 Undefined array key "data" image

kmaphane commented 1 year ago

Okay, somehow the block changes to the below using the layout component and not the blocks component:

<?php extract(collect($attributes->getAttributes())->mapWithKeys(function ($value, $key) { return [Illuminate\Support\Str::camel(str_replace([':', '.'], ' ', $key)) => $value]; })->all(), EXTR_SKIP); ?> @props(['page'])

{{ $slot ?? "" }}
kmaphane commented 1 year ago

Okay this issue really has nothing to do with the package.