form->fill(); } public function form(Form $form): Form { return $form ->schema([ FileUpload::make('file') ->label('فایل اکسل نرخ‌ها') ->acceptedFileTypes([ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel', ]) ->maxSize(5120) ->required() ->disk('local') ->directory('imports'), ]) ->statePath('formData'); } public function downloadTemplate(): void { (new ShippingRatesTemplateExport)->download('IFNEX_Rate_Template.xlsx'); } public function import(): void { $data = $this->form->getState(); if (empty($data['file'])) { Notification::make() ->title('خطا') ->body('لطفاً فایل اکسل را انتخاب کنید.') ->danger() ->send(); return; } $filePath = storage_path('app/' . $data['file']); if (!file_exists($filePath)) { Notification::make() ->title('خطا') ->body('فایل پیدا نشد.') ->danger() ->send(); return; } try { Excel::import(new ShippingRatesImport, $filePath); Notification::make() ->title('موفق') ->body('نرخ‌ها با موفقیت ایمپورت شدند.') ->success() ->send(); $this->form->fill(); } catch (\Exception $e) { Notification::make() ->title('خطا در ایمپورت') ->body($e->getMessage()) ->danger() ->send(); } } }