Artisan Commands

  • php artisan make:api {ControllerName} to generate the controller
  • php artisan make:api:policy to generate a policy file
  • php artisan make:api:resource to geneate the response resource

This will create a Api/ModelNameController for you and you will have the basic routes in place as follows:

  • GET api/v1/{model_name} - list all/paged/filtered (class::index)
  • GET api/v1/{model_name}/$id - Show a specified id (class::show)
  • POST api/v1/{model_name} - Insert a new record (class::store)
  • PUT api/v1/{model_name}/$id - Update an existing record (class::update)
  • **DELETE** api/v1/{model_name}/$id - Delete an existing record (class::destroy)

You can override the methods by simply putting in your own methods to override - method names in braces above

Snake vs Camel Case


There is a middleware to convert all camel to snake: \Phpsa\LaravelApiController\Http\Middleware\SnakeCaseInputs which should go into your Kernal.php file if you wish to automatically convert all incomming requests to snake case.


to automatically convert your response all you need to do is set the request header X-Accept-Case-Type to either snake or camel to alter your data response to either snake-case or camelCase.