I have a resource controller which is ArticleController
and I want to call this controller in web.php
, so I coded:
use AppHttpControllersAdminPanelController; use AppHttpControllersAdminArticleController; Route::namespace('Admin')->prefix('admin')->group(function(){ Route::get('/admin/panel', [PanelController::class, 'index']); Route::resource('articles', [ArticleController::class]); });
Then I tried the command php artisan route:list
to check the routes but I get this error message:
ErrorException
Array to string conversion
So why this error occurs, how can I fix it?
Advertisement
Answer
Route::resource
is expecting a string for the second argument, not an array.
Route::resource('articles', ArticleController::class);
Remove the call to namespace
for the group, you don’t need any namespace prefix because you are using the Fully Qualified Class Name, FQCN, to reference the Controllers.
Route::prefix('admin')->group(function () { Route::get('/admin/panel', [PanelController::class, 'index']); Route::resource('articles', ArticleController::class); });