Reputation: 775
I have upgraded my Laravel application to version 10 and encountered an issue with setting up a route with a namespace. In previous versions of Laravel, I used the following code in my routes/web.php file to set up a route with a namespace:
But in Laravel 10, this doesn't seem to work anymore. I get an "Invalid route action" error with the namespace included in the action parameter.
I've managed to fix my first route on the picture with this code, and now this route works well:
Route::namespace('App\Http\Controllers\Main')->group(function () {
Route::get('/', IndexController::class)->name('main.index');
});
Route::namespace('App\Http\Controllers\Admin')->prefix('admin')->group(function () {
Route::namespace('App\Http\Controllers\Admin\Main')->group(function () {
Route::get('/', App\Http\Controllers\Admin\Main\IndexController::class)->name('main.index');
});
});
Auth::routes();
But I don't know how to fix second route with namespace in namespace.
Can anyone provide guidance on how to properly set up a route with a namespace in Laravel 10? Thank you in advance!
P.S I'm using __invoke() method in my controllers
namespace App\Http\Controllers\Main;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class IndexController extends Controller
{
public function __invoke()
{
return view('main.index');
}
}
Upvotes: 0
Views: 708
Reputation: 5041
I think the namespaces are additive. The first one should be 'App\Http\Controllers\Admin'
and the second should be 'Main'
E.G
Route::namespace('App\Http\Controllers\Admin')->prefix('admin')->group(function () {
Route::namespace('Main')->group(function () {
Route::get('/', App\Http\Controllers\Admin\Main\IndexController::class)->name('main.index');
});
});
Upvotes: 1