Skip to content

Instantly share code, notes, and snippets.

@invaders-xx
Created August 8, 2022 09:49
Show Gist options
  • Save invaders-xx/1e618f08bda0d6e778f225e288266757 to your computer and use it in GitHub Desktop.
Save invaders-xx/1e618f08bda0d6e778f225e288266757 to your computer and use it in GitHub Desktop.
Custom page with action form
<?php
namespace Modules\Traceability\Filament\Resources\ProcessResource\Pages;
use Filament\Forms;
use Filament\Pages\Actions\Action;
use Modules\Traceability\Entities\Company\Process;
use Modules\Traceability\Filament\Page;
class TableDashboard extends Page
{
protected static string $view = 'traceability::pages.table-dashboard';
public $record;
public array $stages = [];
public static function route(string $path): array
{
return [
'class' => static::class,
'route' => $path,
];
}
protected static function shouldRegisterNavigation(): bool
{
return false;
}
public function mount(Process $record): void
{
$this->record = $record;
//abort_unless(auth()->user()->can(), 403);
parent::mount();
$workflow = $this->record->workflow->all();
$this->stages = [];
foreach ($workflow['places'] as $id => $data) {
$this->stages[] = [
'id' => $id,
'title' => $data['metadata']['name'][app()->getLocale()] ?? __('Unknown'),
];
}
}
protected function getTitle(): string
{
return $this->record->name;
}
protected function getActions(): array
{
return [
Action::make('collect')
->label(__('Collect'))
->action(function (array $data): void {
ray($data);
})
->form([
Forms\Components\Repeater::make('materials')
->statePath('materials')
->label('Author')
->schema([
Forms\Components\Select::make('material')
->label(__('Material'))
->validationAttribute(__('Material'))
->searchable()
->preload()
->options(auth()->user()->company->materials()->pluck('name', 'id')->sortBy('name')->toArray())
->required(),
Forms\Components\Select::make('supplier')
->label(__('Supplier'))
->validationAttribute(__('Supplier'))
->searchable()
->preload()
->options(auth()->user()->company->suppliers()->pluck('name', 'id')->sortBy('name')->toArray())
->required(),
Forms\Components\TextInput::make('quantity')
->label(__('Quantity'))
->validationAttribute(__('Quantity'))
->numeric()
->required(),
])
->collapsed()
->collapsible()
->minItems(1)
->required(),
]),
];
}
}
@invaders-xx
Copy link
Author

invaders-xx commented Aug 8, 2022

View :

<x-filament::page>
    @foreach($stages as $stage)
        <x-filament::card>
            <x-filament::card.heading>
                {{ $stage['title'] }}
            </x-filament::card.heading>
            <x-filament::hr/>
            <livewire:traceability::process.list-tokens :process="$record" :stage="$stage['id']"
                                                        wire:key="stage-{{$stage['id']}}"/>
        </x-filament::card>
    @endforeach
</x-filament::page>

And those livewires in the foreach are Filament's tables

@invaders-xx
Copy link
Author

invaders-xx commented Aug 10, 2022

Table's action:

Tables\Actions\Action::make('split')
                ->iconButton()
                ->action(fn($record, array $data) => ray($data))
                ->tooltip(__('Split'))
                ->label(__('Split'))
                ->modalWidth('7xl')
                ->modalHeading(fn($record): string => __('Split') . ' : ' . $record->name)
                ->form([
            Forms\Components\Repeater::make('split')
                ->statePath('split')
                ->label(__('Split'))
                ->schema([
                    Forms\Components\Select::make('product_id')
                        ->label(__('Product'))
                        ->options([]),
                ])
                ->collapsible()
                ->collapsed()
                ->defaultItems(2)
                ->minItems(2)
                ->required(),
        ])
                ->icon('gmdi-call-split-o')
                ->color('primary'),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment