->whereDepotId()
->reactive()
Tabs\Tab::make('Depot') ->schema([ Forms\Components\Select::make('depot_id') ->options(Depot::query()->pluck('name', 'id')) ->required() ->live() ->reactive(), ]),
->options(function (Forms\Get $get) { return Product::query() ->where('depot_id', $get('depot_id')) ->pluck('name', 'id'); })
Forms\Components\Repeater::make('Select products') ->relationship('items') ->required() ->live() ->schema([ Forms\Components\Select::make('product_id') ->label(__('depot_deliveries.create.product_id')) ->options(function (Forms\Get $get) { return Product::query() ->where('depot_id', $get('depot_id')) ->pluck('name', 'id'); }) ->distinct() ->disableOptionsWhenSelectedInSiblingRepeaterItems() ->reactive() ->live() ->afterStateUpdated(function ($state, Forms\Set $set) { $set('system_quantity', Product::query()->find($state)?->quantity ?? 0); $set('price', Product::query()->find($state)?->price ?? 0); }) ->searchable() ->columnSpanFull() ->required(), ]) ->columns(2),
protected function mutateFormDataBeforeCreate(array $data): array { if(!empty($data['products'])) { $products = $data['products']; foreach ($products as $product) { $dataToInsert = [ 'delivery_id' => 1, 'price' => $product['price'], 'quantity' => $product['quantity'], 'product_id' => $product['product_id'] ]; DeliveryProduct::query() ->insert($dataToInsert); } $data['products'] = null; } return $data;}
exceptions
return [ 'icons' => [ 'navigation' => 'heroicon-o-exclamation-triangle', 'exception' => 'heroicon-o-exclamation-triangle', 'headers' => 'heroicon-o-arrows-right-left', 'cookies' => 'heroicon-o-circle-stack', 'body' => 'heroicon-s-code-bracket', 'queries' => 'heroicon-s-circle-stack', ],];
return [ 'datetime_format' => 'm/d/Y H:i:s', 'date_format' => 'm/d/Y', 'activity_resource' => App\Filament\Resources\ActivityResource::class, 'resources' => [ ... ], 'access' => [ ... ], 'notifications' => [ ... ], 'models' => [ ... ], 'custom' => [ // [ // 'log_name' => 'Custom', // 'color' => 'primary', // ] ],];