Thu 02 Nov 2023
By Vanita saini
Web File:Route::prefix('auth')->middleware(['auth'])->group(function(){ //Route::view('/','auth.dashboard'); Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard')->middleware('auth'); Route::resource('/posts', PostController::class); Route::resource('/stations', StationController::class); Route::resource('/airqualities', AirqualityController::class); Route::get('/airqualities/import',[AirqualityController::class, 'import'])->name('airqualities.import'); Route::post('/airqualities/import',[AirqualityController::class, 'importSave'])->name('airqualities.importSave'); Route::resource('/categories', CategoryController::class); Route::get('/categories/download/{filename}',[CategoryController::class, 'download'])->name('categories.download'); Route::resource('/modules', ModuleController::class); Route::get('/modules/download/{filename}/{filetype?}',[ModuleController::class, 'download'])->name('modules.download');});Controller File:- public function import() { dd("dsadsadsad"); return view('auth.airqualities.import'); } public function importSave(Request $request) { return view('auth.airqualities.import'); }Import File:-<?phpnamespace App\Imports;use App\Models\Airquality;use Maatwebsite\Excel\Concerns\ToModel;class AirqualitiesImport implements ToModel{ /** * @param array $row * * @return \Illuminate\Database\Eloquent\Model|null */ public function model(array $row) { return new Airquality([ 'station_id' => $row[0], 'NO' => $row[1], 'NO2' => $row[2], 'NOx' => $row[3], 'NH3' => $row[4], 'SO2' => $row[5], 'CO' => $row[6], 'O3' => $row[7], 'PM25' => $row[8], 'PM10' => $row[9], 'airquality' => $row[10], 'AQI' => $row[11] ]); }}adssd