V
V
Vladimir Singhtlov2018-08-15 09:31:47
Laravel
Vladimir Singhtlov, 2018-08-15 09:31:47

When requested, the route goes to the wrong controller, what could be the problem?

Route::prefix('records')
                    ->namespace('Records')
                    ->as('records.')->group(function () {
                        Route::get('/', '[email protected]')->name('index');

                        Route::prefix('{file}')
                            ->as('file.')->group(function () {
                            Route::get('/', '[email protected]')->name('show');
                            Route::post('/', '[email protected]')->name('take');
                            Route::put('/', '[email protected]')->name('update');
                        });

                        Route::prefix('messages')->as('messages.')->group(function () {
                            Route::post('/', '[email protected]')->name('index');
                            Route::put('/', '[email protected]')->name('store');
                            Route::prefix('{message}')->group(function () {
                                Route::delete('/', '[email protected]')->name('destroy');
                            });
                        });
                    });

When I ajax with the records.file.show route to records.messages.store, it throws an error that occurs because the records.messages.store route goes to the wrong controller? What can go wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2018-08-15
@singhtless

Set prefix messages before prefix {file}. And another controller works for you, since "messages" gets into {file} - and this is any value. If you set prefix messages earlier, then the controller you need will be in priority.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question