I have a problem when trying to set routes after the first one.
this is my routes :
Route::group([
'prefix' => 'atribut',
'as' => 'atribut.'
], function () {
Route::group(['prefix' => 'tabHome', 'as' => 'tabHome.'], function () {
Route::get('', [AtributDashboardController::class, 'showTab'])->name('showTab');
Route::post('', [AtributDashboardController::class, 'addDataFirst'])->name('addDataFirst');
Route::get('deleteDataFirst/{id}', [AtributDashboardController::class, 'deleteDataFirst'])->name('deleteDataFirst');
Route::post('', [AtributDashboardController::class, 'addDataSecond'])->name('addDataSecond');
Route::get('deleteDataSecond/{id}', [AtributDashboardController::class, 'deleteDataSecond'])->name('deleteDataSecond');
});
});
i already set method in controller for both add and delete for both data first and data second
in first view i have a form action :
{{route('frontend.atribut.tabHome.addDataFirst')}}
it is the same for second view :
{{route('frontend.atribut.tabHome.addDataSecond')}}
but i get this error :
Route [frontend.atribut.tabHome.addDataFirst] not defined.
What makes me confused is, when i remove all code related to data second (in both controller and routes) the project can run fine and execute the code for data first.
Basically i have 2 view and each one have form, but the first view can run fine. After i add the same code for second view, i get the error.
CodePudding user response:
Both routes use the same URL Route::post('', ...)
. The second one overwrites the first one. Make your URLs unique like you did with your deleteDataSecond
routes:
Route::post('addDataFirst', [AtributDashboardController::class, 'addDataFirst'])->name('addDataFirst');
and
Route::post('addDataSecond', [AtributDashboardController::class, 'addDataSecond'])->name('addDataSecond');