Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kris01's avatar

Laravel route not found 404, but the route exists

In laravel, I have the following route

            Route::post('/device/save',                           'Admin\DeviceController@save')->name('admin.device.save');

I already checked if there is a name conflict with other routes, but there isn't, I also tried giving it different names and urls, but nothing works, even random names, but I stil get 404.

This is how I call with with vue inertia

 let url = route('admin.device.save');
      form.post(url, {
          preserveScroll: true,
          onStart: () => Spinner.content({content:"Saving Device.."}),
          onSuccess: () => {Alert.success(Inertia.page.props.flash.success.message); Spinner.hide(); },
      });

what could be the problem?

0 likes
22 replies
vincent15000's avatar

Have you cached the routes ?

Is there other similar routes created using resource ?

1 like
Kris01's avatar

@vincent15000 I did cache the routes, both using php artisas optimize:clear then php artisan optimize and using php artisan cache:route

I do not have any similar routes with resource, the weird thing is I also tried to give it a random name, and still nothing, i also create a create route which works just fine.

1 like
Kris01's avatar

@vincent15000 What other reasons could there be for it to not find the route ?

my routes are in a file called admin.php how when i do route:list it shows only those inside web.php, how can I check the admin.php ones ?

1 like
Kris01's avatar

@krisi_gjika every other route inside admin.php is working just fine, this is the only one giving problems.

1 like
vincent15000's avatar

@Kris01 Oh ok ... you have to load the admin.php routes inside the RouteServiceProvider.php file.

1 like
Kris01's avatar

@vincent15000 Already loaded

 protected function mapAdminRoutes()
    {
        Route::middleware('admin')
            ->namespace($this->namespace)
            ->group(base_path('routes/admin.php'));
    }
1 like
vincent15000's avatar

@Kris01

public function boot(): void
{
    RateLimiter::for('api', function (Request $request) {
        return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
    });

    $this->routes(function () {
        Route::middleware('api')
            ->prefix('api')
            ->group(base_path('routes/api.php'));

        Route::middleware('web')
            ->group(base_path('routes/web.php'));

        Route::middleware('admin')
            ->group(base_path('routes/admin.php'));
    });
}
2 likes
Kris01's avatar

@vincent15000 I checked better and on route:list the route is returned

|        | POST          | admin/device/save                                                                                                   | admin.device.save                                                 | App\Http\Controllers\Admin\DeviceController@save                                                        | App\Http\Middleware\AdminCheck                                                                        |
Kris01's avatar

@vincent15000

this is the vue

<template>
    <h2 class="title">Create Device</h2>
    <DevicesForm
      :providers="providers"
      @saveDevice="saveDevice"
    >
    </DevicesForm>
  </template>
  <script setup>
  import { ref } from "@vue/reactivity";
  import { Inertia } from "@inertiajs/inertia";
  import CompanyDetailsMenu from "../../modules/companies/components/CompanyDetailsMenu.vue";
  import DevicesForm from "../../modules/devices/components/DevicesForm.vue";
  import Alert from "../../../shared/services/BaseAlert";
  import Spinner from "../../../shared/services/GlobalSpinnerController";
  
  const props = defineProps({
    providers: Object,
  });
  
  const saveDevice = (form) => {
      let url = route('admin.device.save');
      form.post(url, {
          preserveScroll: true,
          onStart: () => Spinner.content({content:"Saving Device.."}),
          onSuccess: () => {Alert.success(Inertia.page.props.flash.success.message); Spinner.hide(); },
      });
  }
  </script>
  
1 like
vincent15000's avatar

@Kris01 Ok so you are using the route() helper in VueJS ? It can't work. You have to write the route itself and not its name.

Unless you are using Ziggy ?

What do you see in the console if you type console.log(url); just after having defined the variable in the saveDevice function ?

1 like
Kris01's avatar

@vincent15000

I am using Ziggy, on console.log(url) I am seeing the whole url as it should be.

If i do conole.log(form.post(url)) it is undefined I don't know maybe if it has something to do with the problem

1 like
krisi_gjika's avatar

are you sure it's the route that is giving the 404? That can also be a findOrFail in your code or a missing route binding.

2 likes
Kris01's avatar

@krisi_gjika To make sure it is not some problem inside the controller, I commented out all the functionality and calcuation of the function, and I just left a dump('hello'), but unfortunately same.

Really really strange problem, I do not understand everythign seems fine.

1 like
Kris01's avatar

@krisi_gjika You are right, there was an authorization check inside the form request

1 like

Please or to participate in this conversation.