Getting 404 error

  Thu 02 / 11 / 2023

  Posted by: Vanita saini

Category : Laravel

Tags : laravel , php laravel

Description

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:-

<?php

namespace 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



View Code
                        Hello Sir, I'm using excel library to import bulk data, but i don't know why i m getting 404 error even i have cross check all the routes and methods. please guide me where i m wrong. My file name start with Airquality.
                
  Comment   Share
0 Likes   2 Comments


comment-author
Vanita saini Author

Sir, now the issue is resolved, but I don't know how it was resolved. I just changed the route sequence. please guide me what rule we should follow when define any routes. Route::prefix('auth')->middleware(['auth','isAdmin'])->group(function(){ //Route::view('/','auth.dashboard'); Route::get('/dashboard', [DashboardController::class, 'dashboard'])->name('dashboard'); Route::resource('/posts', PostController::class); Route::resource('/categories', CategoryController::class); Route::resource('/stations', StationController::class); Route::get('/airqualities/import',[AirqualityController::class, 'import'])->name('airqualities.import'); Route::post('/airqualities/import',[AirqualityController::class, 'importSave'])->name('airqualities.importSave'); Route::resource('/airqualities', AirqualityController::class); Route::get('/categories/download/{filename}',[CategoryController::class, 'download'])->name('categories.download'); Route::get('/categories/remove/{id}',[CategoryController::class, 'remove'])->name('categories.remove'); Route::resource('/modules', ModuleController::class); Route::get('/modules/download/{filename}/{filetype?}',[ModuleController::class, 'download'])->name('modules.download'); Route::post('/posts/get-additional-fields', [PostController::class, 'getAdditionalFields'])->name('posts.get-additional-fields'); }); i just placed get, post urls above the resource urls.



Reply


commented 1 year ago
comment-author
Hadayat Niazi Super Admin

your main issue was your resource route is overriding your one of the method that's you are facing this issue.



comment-author
Hadayat Niazi Super Admin

These rules are based on your need, in your case the problem is your resource route is replacing one of your custom route that's the main issue, and you will still face this in opening the resource route, so it's better to change the custom route URL little bit different from the resource route.



comment-author
Hadayat Niazi Super Admin

Where you are using AirqualitiesImport, you are just showing your routes and controller method which are opening views, please share the code where you are getting error. Also please post the description and code in the correct section, you are posting your code inside description and writing description inside code, please write it correctly. Thanks for the understanding.



Reply


commented 1 year ago