Created
August 8, 2022 09:49
-
-
Save invaders-xx/1e618f08bda0d6e778f225e288266757 to your computer and use it in GitHub Desktop.
Custom page with action form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(), | |
]), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Table's action: