schema([ Section::make([ Section::make([ Select::make('order_type') ->required() ->options(OrderType::class) ->searchable(), Split::make([ Select::make('customer_id') ->required() ->label('Customer') ->options(Customer::all()->pluck('company_name', 'id')) ->reactive() ->searchable(), Select::make('contact_id') ->label('Contact') ->options(fn ($get): array => Contact::where('customer_id', $get('customer_id') ?? null)->get()->pluck('full_name', 'id')->toArray()) ->searchable(), ]), TextInput::make('customer_po') ->required() ->label('Customer PO'), Split::make([ DatePicker::make('order_date') ->required() ->default(today()), DatePicker::make('due_date') ->required() ->default(today()->add('10 days')), ]), ])->columnSpan(1), Section::make([ ToggleButtons::make('status') ->required() ->options(OrderStatus::class) ->inline(), ToggleButtons::make('order_attributes') ->options(OrderAttributes::class) ->multiple() ->inline(), Textarea::make('notes') ->rows(3), ])->columnSpan(1), ])->columns(2), TableRepeater::make('Order Products') ->relationship('orderProducts') ->label('Garments') ->schema([ TextInput::make('sku'), TextInput::make('product_name'), TextInput::make('color'), Cluster::make([ TextInput::make('xs') ->placeholder('xs'), TextInput::make('s') ->placeholder('s'), TextInput::make('m') ->placeholder('m'), TextInput::make('l') ->placeholder('l'), TextInput::make('xl') ->placeholder('xl'), TextInput::make('2xl') ->placeholder('2xl'), TextInput::make('3xl') ->placeholder('3xl'), TextInput::make('osfa') ->placeholder('osfa'), ]) ->label('Sizes'), ]) ->reorderable() ->cloneable(), Repeater::make('Services') ->relationship('productServices') ->label('Production Details') ->schema([ Grid::make(19) ->schema([ TextInput::make('service_type') ->datalist([ 'Embroidery', 'SCP', 'Vinyl', 'Editing', 'Digitizing', ]) ->columnSpan(2), TextInput::make('placement') ->columnSpan(3), TextInput::make('serviceFileName') ->columnSpan(3) ->label('Logo Name'), TextInput::make('serviceFileSetupNumber') ->label('Setup') ->columnSpan(1), Cluster::make([ TextInput::make('serviceFileWidth') ->prefix('w') ->placeholder('Width'), TextInput::make('serviceFileHeight') ->prefix('h') ->placeholder('Height'), ]) ->label('Dimensions') ->columnSpan(4), TextInput::make('amount') ->label('Quantity') ->prefix('#') ->columnSpan(2), TextInput::make('amount_price') ->prefix('$') ->columnSpan(2), TextInput::make('total_price') ->prefix('$') ->readOnly() ->columnSpan(2), ]), Grid::make(9) ->schema([ TextInput::make('serviceFileCode') ->label('Code') ->columnSpan(1) ->placeholder('A1234'), Textarea::make('notes') ->placeholder('Thread colors...') ->columnSpan(8), ]), ]) ->reorderable() ->cloneable() ->columns(4) ->columnSpan(2) ->mutateRelationshipDataBeforeSaveUsing(function (array $data, ProductService $record): array { dd('yep'); Log::debug($record->toJson()); if ($record->serviceFile !== null) { $record->serviceFile->update([ 'name' => $data['serviceFileName'], 'width' => $data['serviceFileWidth'], 'height' => $data['serviceFileHeight'], 'code' => $data['serviceFileCode'], 'setup_number' => $data['serviceFileSetupNumber'], ]); } return $data; }) ->mutateRelationshipDataBeforeFillUsing(function (array $data): array { /** @var ProductService $productService */ $productService = ProductService::findOrFail($data['id']); $serviceFile = ServiceFile::findOrFail($productService->service_file_id); if ($serviceFile !== null) { $data['serviceFileName'] = $serviceFile->name; $data['serviceFileWidth'] = $serviceFile->width; $data['serviceFileHeight'] = $serviceFile->height; $data['serviceFileCode'] = $serviceFile->code; $data['serviceFileSetupNumber'] = $serviceFile->setup_number; } return $data; }), // ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array { // $serviceFile = ServiceFile::create([ // 'name' => $data['serviceFileName'], // 'width' => $data['serviceFileWidth'], // 'height' => $data['serviceFileHeight'], // 'code' => $data['serviceFileCode'], // 'setup_number' => $data['serviceFileSetupNumber'], // ]); // // return $data; // }), ]); } public static function table(Table $table): Table { return $table ->columns([ TextColumn::make('internal_po') ->label('Internal PO') ->fontFamily('mono') ->color('info') ->searchable() ->sortable(), TextColumn::make('customer.company_name') ->searchable() ->sortable(), TextColumn::make('customer_po') ->label('PO') ->wrap() ->weight('bold') ->color('code') ->searchable() ->sortable(), TextColumn::make('order_date') ->searchable() ->sortable(), TextColumn::make('due_date') ->searchable() ->sortable(), TextColumn::make('status') ->badge() ->searchable() ->sortable(), ]) ->defaultSort('order_date', 'desc') ->groups([ 'status', ]) ->filters([ Tables\Filters\SelectFilter::make('status') ->multiple() ->options(OrderStatus::class), ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]); } public static function getRelations(): array { return [ ]; } public static function getPages(): array { return [ 'index' => Pages\ListOrders::route('/'), 'create' => Pages\CreateOrder::route('/create'), // 'view' => Pages\ViewOrder::route('/{record}'), 'edit' => Pages\EditOrder::route('/{record}/edit'), ]; } }