I have created the two resource controller inside two different route groups. One for User One for Admin
Route::group([ 'prefix' => 'dashboard', "middleware" => 'auth', "namespace" => 'User' ], function (){ Route::resource('projects', 'ProjectController'); }) Route::group([ 'prefix' => 'admin', "middleware" => 'auth', "namespace" => 'Admin' ], function (){ Route::resource('projects', 'ProjectController'); })
I am using the ‘route’ keyword for assigning the routes. I am doing so because I wanted to use same views files for both.
Here is the blade file
<form action='{{route('projects.update', $project)}}' method="POST"> @method('PUT') @csrf .... </form>
When I am in /admin/projects it is using the admin.projects resource routes as expected but when I am /dashboard/projects it should use dashboard resource route, but it is using admin.projects.update route.
And also When I comment/remove the admin projects routes from the web.php, it’s working fine.
Let me know why it is happening. And what is the best solution for this.
Advertisement
Answer
Run this command php artisan route:list
and you will found the same alias name in both so you have to make alias unique.
To do so,
Route::group([ 'prefix' => 'dashboard', 'as' => 'dashboard.', "middleware" => 'auth', "namespace" => 'User' ], function (){ Route::resource('projects', 'ProjectController'); }); Route::group([ 'prefix' => 'admin', 'as' => 'admin.', "middleware" => 'auth', "namespace" => 'Admin' ], function (){ Route::resource('projects', 'ProjectController'); });
So you need to use this as admin.projects.index
and dashboard.projects.index