Framework: Route::apiResource() doesn't accept arrays

Created on 18 Mar 2018  ·  6Comments  ·  Source: laravel/framework

  • Laravel Version: 5.6.11
  • PHP Version: 7.1.9
  • Database Driver & Version: mysql (unknown version)

Description:

So I noticed this today and I assume it's a doc mistake, but who knows its actually a bug. When creating multiple resource controllers, the docs say

You may register many API resource controllers at once by passing an array to the apiResources method:

Route::apiResources([
   'photos' => 'PhotoController',
   'posts' => 'PostController'
]);

But for me it's saying

In Router.php line 329:

Type error: Too few arguments to function Illuminate\Routing\Router::apiResource(), 1 passed in [...]\vendor\laravel\frameworksrc\Illuminate\Support\Facades\Facade.php on line 221 and at least 2 expected

Steps To Reproduce:

  • Create one or more resource controllers
    Example: php artisan make:controller Api/FooController --resource --api
  • Add a Route::apiResource and pass all the made controllers in an array to that method

Example:

Route::apiResource([
    'foo' => 'Api\Foocontroller'
]);
  • Execute php artisan route:list and see the error

Most helpful comment

You have a typo: apiResource()apiResources()

All 6 comments

You have a typo: apiResource()apiResources()

Oh gosh, ok thanks for pointing out @staudenmeir 🤦‍♂️

I was missing a 's' as well. Thanks :laughing:

But why in the documentation of laravel is written without "s"?
Route::resource('photos.comments', 'PhotoCommentController');

@josendulip Both methods exist: https://laravel.com/docs/controllers#restful-partial-resource-routes

You have a typo: apiResource()apiResources()

it works for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainSauvaire picture RomainSauvaire  ·  3Comments

lzp819739483 picture lzp819739483  ·  3Comments

ghost picture ghost  ·  3Comments

JamborJan picture JamborJan  ·  3Comments

fideloper picture fideloper  ·  3Comments