Search code examples
phpapilaravelroutesdingo-api

dingo\api $api router instance in routes.php causes an error


Argument 2 passed to Dingo\Api\Exception\Handler::__construct() must be of the type array, null given, called in C:\wamp\www\clientdata\vendor\dingo\api\src\Provider\ApiServiceProvider.php on line 125 and defined in Handler.php line 53

I randomly received this error without changing anything on my old project, so I have done a fresh Laravel install, and then added Dingo API to my composer.json as so

"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "dingo/api": "1.0.x@dev"
},

and added $api = app('Dingo\Api\Routing\Router'); to my routes, along with a basic route. But the only thing that gets rid of this problem is removing the above line from routes.php


Solution

  • It's because I put the Dingo service provider at the bottom of the array, rather than first as is suggested in the installation guide.

    Dingo\Api\Provider\LaravelServiceProvider::class