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

Sven0188's avatar

Routes Issue = "Route not defined"

Good day to All,

I am really having difficulty to solve the next challenge.

All my routes worked prefectly but then I re-organized them in order to make for better logical sense. What I mainly did was to remove some routes out from a group. But for the hell of it now all is broken.

Routes.php: Route::group(["prefix" => "admin"], function() { Route::get("/", ["as" => "companies.all", "uses" => "CompanyController@index"]); Route::post("/store", ["as" => "company.store", "uses" => "CompanyController@store"]); Route::post("/delete", ["as" => "company.delete", "uses" => "CompanyController@destroy"]); Route::group(["prefix" => "company"], function() { Route::get("/{id}", ["as" => "company.view", "uses" => "CompanyController@setup"]); } }

companies\view.blade.php - Code in the View which raises the error: {{ Form::open(["route" => ["company.store"], "method" => "POST", "id" => "formNew"]) }}

And the Error Message: Route [company.view] not defined. (View: C:\xampp\htdocs\prodx\resources\views\companies\view.blade.php)

I am working on Laravel 5.2 latest.

I have run artisan commands: cache:clear and also composer: clearcache & dumpautoload.

Any suggestions out there please ?

Thanks ALL !!!! :)

0 likes
9 replies
Sven0188's avatar

Ooh I actually cleared browser cache as well. Restarted apache. Tried everything out of desperation :)

Oops and my controller method: public function index() { $companies = Company::orderBy("company_name", "asc")->get(); return View::make("companies.view", ["companies" => $companies]); }

bobbybouwmann's avatar

Your problem is not in your routes, but in closing the route groups. You end them with a }. However you need to end them with this });

It basically means you are not closing the function (the callback function as it's called)

Here is an example

Route::group(["prefix" => "company"], function() { 
    Route::get("/{id}", ["as" => "company.view", "uses" => "CompanyController@setup"]);
});
Sven0188's avatar

Sorry that was I typo - here is my complete routes file:

Route::get('/', function() { return "Login Page Here " . route("company.view"); });

Route::group(["prefix" => "admin"], function() {

Route::get("/", ["as" => "companies.all", "uses" => "CompanyController@index"]);
Route::post("/store", ["as" => "company.store", "uses" => "CompanyController@store"]);
Route::post("/delete", ["as" => "company.delete", "uses" => "CompanyController@destroy"]);  

Route::group(["prefix" => "company"], function() {

    Route::get("/{id}", ["as" => "company.view", "uses" => "CompanyController@setup"]);
    Route::post("/store", ["as" => "company.store", "uses" => "CompanyController@store"]);
    Route::post("/delete", ["as" => "company.delete", "uses" => "CompanyController@destroy"]);  

    Route::group(["prefix" => "company"], function() {
        // Route::get("/", ["as" => "company.view", "uses" => "CompanyController@index"]);
    });

    // Route::group(["prefix" => "department"], function() {
        Route::get("/{id}", ["as" => "department.view", "uses" => "DepartmentController@index"]);
        Route::post("/delete", ["as" => "department.delete", "uses" => "DepartmentController@destroy"]);    
        Route::post("/store", ["as" => "department.store", "uses" => "DepartmentController@store"]);
    // });

    // Route::group(["prefix" => "machine"], function() {
        Route::get("/", ["as" => "machine.view", "uses" => "MachineController@index"]);
        Route::put("/update", ["as" => "machine.update", "uses" => "MachineController@update"]);
        Route::post("/delete", ["as" => "machine.delete", "uses" => "MachineController@destroy"]);  
    // });

    // Route::group(["prefix" => "tool"], function() {
        Route::get("/", ["as" => "tool.view", "uses" => "ToolController@index"]);
        Route::put("/update", ["as" => "tool.update", "uses" => "ToolController@update"]);
        Route::post("/delete", ["as" => "tool.delete", "uses" => "ToolController@destroy"]);    
    // });

    // Route::group(["prefix" => "rejecttype"], function() {
        Route::get("/", ["as" => "rejecttype.view", "uses" => "RejectTypeController@index"]);
        Route::put("/update", ["as" => "rejecttype.update", "uses" => "RejectTypeController@update"]);
        Route::post("/delete", ["as" => "rejecttype.delete", "uses" => "RejectTypeController@destroy"]);    
    // });

    // Route::group(["prefix" => "rejectreason"], function() {
        Route::get("/", ["as" => "rejectreason.view", "uses" => "RejectReasonController@index"]);
        Route::put("/update", ["as" => "rejectreason.update", "uses" => "RejectReasonController@update"]);
        Route::post("/delete", ["as" => "rejectreason.delete", "uses" => "RejectReasonController@destroy"]);    
    // });  

    // Route::group(["prefix" => "downtimetype"], function() {
        Route::get("/", ["as" => "downtimetype.view", "uses" => "DowntimeTypeController@index"]);
        Route::put("/update", ["as" => "downtimetype.update", "uses" => "DowntimeTypeController@index@update"]);
        Route::post("/delete", ["as" => "downtimetype.delete", "uses" => "DowntimeTypeController@destroy"]);    
    // });

    // Route::group(["prefix" => "downtimereason"], function() {
        Route::get("/", ["as" => "downtimereason.view", "uses" => "DowntimeReasonController@index"]);
        Route::put("/update", ["as" => "downtimereason.update", "uses" => "DowntimeReasonController@update"]);
        Route::post("/delete", ["as" => "downtimereason.delete", "uses" => "DowntimeReasonController@destroy"]);    
    // });  
});

}); Route::group(["prefix" => "home"], function() { Route::get("/", ["as" => "home.index", "uses" => "AppController@indexHome"]); });

Sven0188's avatar

Mmm last two lines should be in the code block - apologizes

Sven0188's avatar

And for testing purpose, if I remove the route name from the view: {{ route('company.view', $company['id']) }} then it is working.

bobbybouwmann's avatar

So the problem is in your your company.view route.

You have a so called "catch all" route right now. You should place that on at the bottom of your group. Laravel will always pick the first route it's find. Now when you have a route like /{id} it will always be the first, since id doesn't say anything about being an integer or a string an so on.

So the simple fix is, move that "catch all" route to the bottom and it's fixed ;)

cnsair's avatar

Good day guys. I am kinda new to Laravel and don't know much.

I have a similar issue: I have 5 routes with the dynamic URI {foo}. Laravel seems to pick the first one. I know this because I have swapped these routes and the first one is always picked. Please how can I overcome this? I have searched online and tried many things, but none of them have provided a permanent solution. Below is a snippet of my code. Please pay attention to the delete route (/uploads/show/{foo})

//Update Route::patch('/uploads/edit-summary/{summary}', [ SummaryController::class, 'update' ])->name('summary.update');

//delete Route::delete('/uploads/show/{summary}', [ SummaryController::class, 'destroy' ])->name('summary.destroy');

//Update Route::patch('/uploads/edit-education/{education}', [ EducationController::class, 'update' ])->name('education.update');

//delete Route::delete('/uploads/show{education}', [ EducationController::class, 'destroy' ])->name('education.destroy');

//Update Route::patch('/uploads/edit-experience/{experience}', [ ExperienceController::class, 'update' ])->name('experience.update');

//delete Route::delete('/uploads/show/{experience}', [ ExperienceController::class, 'destroy' ])->name('experience.destroy');

JussiMannisto's avatar

@cnsair This thread is 8 years old and from a very old version of Laravel. You should make a new thread in the future. You should also format your code so that it's readable.

Don't use the identical paths for different resources. Right now you have these two routes:

Route::delete('/uploads/show/{summary}', [SummaryController::class, 'destroy'])
	->name('summary.destroy');

Route::delete('/uploads/show/{experience}', [ExperienceController::class, 'destroy'])
	->name('experience.destroy');

Now imagine that Laravel receives a delete request with a path of /uploads/show/35. How is it supposed to know which route to use? You need to use different paths for different resources, for example:

Route::delete('/summaries/{summary}', [SummaryController::class, 'destroy'])
	->name('summaries.destroy');

Route::delete('/experiences/{experience}', [ExperienceController::class, 'destroy'])
	->name('experiences.destroy');

See here how resource routes are typically named: https://laravel.com/docs/11.x/controllers#actions-handled-by-resource-controllers

Btw, your education.destroy route url missing a slash: /uploads/show{education}

1 like
amitsolanki24_'s avatar

@cnsair hello, first of all you need to create a new post for your issue.

I saw your code this is happening because your delete routes are same.

Please try these delete routes

Route::delete('/summaries/{summary}', [ SummaryController::class, 'destroy' ])->name('summary.destroy');

Route::delete('/educations/{education}', [ EducationController::class, 'destroy' ])->name('education.destroy');

Route::delete('/experiences/{experience}', [ ExperienceController::class, 'destroy' ])->name('experience.destroy');

Please or to participate in this conversation.