简体   繁体   中英

Laravel 8: Array to string conversion while route:list

PS C:\xampp\htdocs\ecommerce33> php artisan route:list

ErrorException

Array to string conversion

at C:\xampp\htdocs\ecommerce33\vendor\laravel\framework\src\Illuminate\Routing\ResourceRegistrar.php:416

  412▕     protected function getResourceAction($resource, $controller, $method, $options)
  413▕     {
  414▕         $name = $this->getResourceRouteName($resource, $method, $options);
  415▕ 
➜ 416▕         $action = ['as' => $name, 'uses' => $controller.'@'.$method];
  417▕ 
  418▕         if (isset($options['middleware'])) {
  419▕             $action['middleware'] = $options['middleware'];
  420▕         }

I tried the command php artisan route:list to check the routes but I get this error message:

So why this error occurs, how can I fix it?

This Is The Web Route Page

Route::get('/', function () {
    return view('welcome');
});

Auth::routes(['verify'=>true]);

Route::get('/user' ,[indexController::class , 'index'])->middleware('auth' ,'check.user')->name('user');

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::middleware('auth','check.user')->prefix("user")->group(function() {

    Route::get('/addToCart/{product}', [App\Http\Controllers\User\indexController::class, 'addToCart'])->name('cart.add');

    Route::get('shopping-cart', [App\Http\Controllers\User\indexController::class, 'showcart'])->name('cart.show');

    Route::resource("/profile", 'App\Http\Controllers\User\indexController');

    Route::resource("product", [App\Http\Controllers\User\indexController::class , 'product']);

    Route::get('/search', [App\Http\Controllers\SearchController::class, 'index'])->name('search');
});

Your definition for the product resource is incorrect. You should adjust it to passing a string as the second argument:

Route::resource('product', App\Http\Controllers\User\indexController::class);

The second argument to resource is a string, which is the Controller. There is no method specified as resources are particular things which define individual routes with actions to multiple methods of that particular controller.

Though, you already have profile using this Controller and defined as a resource so not sure the reason to then have the same routes but as the product resource.

Perhaps you meant to just create a GET route for that one method?:

Route::get('product', [App\Http\Controllers\User\indexController::class, 'product'])->name('product');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM