schema([ Select::make('spice_id') ->label('Rohstoff') ->relationship('spice', 'name') ->required() ->preload() ->searchable(), Select::make('supplier_id') ->label('Lieferant') ->relationship('supplier', 'name') ->required() ->preload() ->searchable(), TextInput::make('amount') ->label('Liefermenge') ->numeric() ->required() ->rules(['min:0.01']) ->disabled(fn($record) => !is_null($record)), DatePicker::make('supplied_at') ->label('Lieferdatum') ->default(now()) ->required(), ]); } public static function table(Table $table): Table { return $table ->columns([ TextColumn::make('spice.name')->label('Rohstoff')->searchable(), TextColumn::make('supplier.name')->label('Lieferant')->searchable(), TextColumn::make('amount')->label('Liefermenge'), TextColumn::make('supplied_at')->label('Lieferdatum')->date('d.m.Y'), // Lieferdatum in der Tabelle anzeigen ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make(), ]); } protected static function getTableActions(): array { return [ DeleteAction::make() ->before(function ($record, DeleteAction $action) { // Custom check logic if (true) { // Notify user about the restriction Notification::make() ->title('Deletion Error') ->body("This record cannot be deleted because it has related records.") ->status('danger') ->send(); // Cancel the deletion $action->cancel(); } }), ]; } public static function getRelations(): array { return []; } public static function getPages(): array { return [ 'index' => Pages\ListSpiceSuppliers::route('/'), 'create' => Pages\CreateSpiceSupplier::route('/create'), 'edit' => Pages\EditSpiceSupplier::route('/{record}/edit'), ]; } public static function getPluralLabel(): string { return 'Rohstofflieferungen'; } }