Hello everyone, I have an issue while trying to use a custom Livewire component inside a modal for a resource (I'm using the --simple version with ManageMyResource).
I have attached the code related to the Livewire component and the Filament resource. I would prefer not to use a full-page Livewire component but just be able to render the custom form inside the modal.
ManageResource:
<?php
namespace App\Filament\Resources\OpenFundsPatternResource\Pages;
use App\Filament\Resources\OpenFundsPatternResource;
use Filament\Actions;
use Filament\Resources\Pages\ManageRecords;
class ManageOpenFundsPatterns extends ManageRecords
{
protected static string $resource = OpenFundsPatternResource::class;
protected function getHeaderActions(): array
{
return [
//Actions\CreateAction::make()
//Not Working!! :(
Actions\CreateAction::make()->modalContent(view('livewire.create-open-funds-d')),
];
}
}
Resource:
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\OpenFundsPatternResource\Pages;
use App\Models\OpenfundsD;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Carbon\Carbon;
class OpenFundsPatternResource extends Resource
{
protected static ?string $model = OpenfundsD::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Open Funds';
protected static ?string $navigationLabel = 'Open Funds Patterns';
public static function form(Form $form): Form
{
return $form
->schema([
/*Forms\Components\TextInput::make('ckey')
->label('Header Originale')
->required(),
Forms\Components\TextInput::make('cvalue')
->label('Header Finale')
->required(),
Select::make('open_funds_lunivid')
->relationship(name: 'OpenfundsT', titleAttribute: 'cfilename') */
//CreateAction::make()->modalContent(view('livewire.create-open-funds-d'))
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('lunivid')
->label('id')
->toggleable()
->sortable(),
TextColumn::make('ckey')
->label('Header Originale')
->toggleable()
->searchable(),
TextColumn::make('cvalue')
->label('Header Finale')
->toggleable()
->searchable(),
TextColumn::make('tuts')
->toggleable()
->sortable()
->label('Data')
->dateTime("Y-m-d H:i:s", 'Europe/Rome'),
])
->filters([
Filter::make('tuts')
->form([
DatePicker::make('creato_da'),
DatePicker::make('creato_al'),
])
->query(function (Builder $query, array $data): Builder {
//dd($data);
return $query
->when(
$data['creato_da'] ?? null,
fn (Builder $query, $date): Builder => $query->whereDate('tuts', '>=', $date),
)
->when(
$data['creato_al'] ?? null,
fn (Builder $query, $date): Builder => $query->whereDate('tuts', '<=', $date),
);
})
->indicateUsing(function (array $data): array {
$indicators = [];
if ($data['creato_da'] ?? null) {
$indicators['creato_da'] = 'Ordina da ' . Carbon::parse($data['creato_da'])->toFormattedDateString();
}
if ($data['creato_al'] ?? null) {
$indicators['creato_al'] = 'Order until ' . Carbon::parse($data['creato_al'])->toFormattedDateString();
}
return $indicators;
}),
])
->actions([
Tables\Actions\EditAction::make()
->label('')
->size('lg'),
Tables\Actions\DeleteAction::make()
->label('')
->size('lg'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ManageOpenFundsPatterns::route('/'),
];
}
}
Livewire Custom Component (actually a form, i need to do a custom drag and drop with js)
<?php
namespace App\Livewire;
use Livewire\Component;
use App\Models\Post;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Illuminate\Contracts\View\View;
class CreateOpenFundsD extends Component implements HasForms
{
use InteractsWithForms;
public ?array $data = [];
public function mount(): void
{
$this->form->fill();
}
public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('ckey')
->label('Header Originale')
->required(),
TextInput::make('cvalue')
->label('Header Finale')
->required(),
Select::make('open_funds_lunivid')
->relationship(name: 'OpenfundsT', titleAttribute: 'cfilename')
])
->statePath('data');
}
public function create(): void
{
dd($this->form->getState());
}
public function render()
{
return view('livewire.create-open-funds-d');
}
}
Livewire View:
<div>
<form wire:submit="create">
{{ $this->form }}
<button type="submit">
Submit
</button>
</form>
<x-filament-actions::modals />
</div>
This way im getting this error:
Too few arguments to function Filament\Resources\Pages\ListRecords::form(), 0 passed in /home/alby/pautoimporta/vendor/filament/actions/src/Concerns/InteractsWithActions.php on line 308 and exactly 1 expected
Can anyone help me with this problem?
Thank you very much