Laravel PostgreSQL CRUD API Starter

A Laravel 13 CRUD API starter on PHP 8.4 that stores one resource, items, in PostgreSQL through Eloquent, served by Apache from a Dockerfile. It is for PHP developers who want Laravel's API routes only, with no sessions, cookies, views or APP_KEY, and validation, JSON errors, limit and offset paging, a database health check and tests already written.

by Light CloudCRUD APIs

Features

  • GET, POST, PUT and DELETE on /items, with GET /items?limit=20&offset=0 listing oldest first and limit 1 to 100
  • Laravel 13's API routes only, in routes/api.php without the /api prefix, one ItemController and an Eloquent Item model
  • Validation in the controller: name trimmed and 1 to 200 characters, description a string or absent, every failure a 400
  • Every error is { "error": "..." }: 400 for bad input, 404 for an unknown item or route, 405 for a wrong method, 500 without details
  • The items migration applied by the container on start, so a fresh database needs no manual step
  • GET /health answers 200 when the database answers and 503 when it does not; timestamps in ISO 8601 UTC
  • TLS to the database by default (DB_SSLMODE=require), and DB_HOST may carry a port as host:port
  • 23 PHPUnit tests against a real PostgreSQL in a separate laravel_testing database, plus Laravel Pint

Tech stack

What you need

  • A paid plan: deploying creates a PostgreSQL database, which the Free plan does not include
  • To run it locally: PHP 8.3 or newer with pdo_pgsql, Composer, and Docker for a local PostgreSQL
  • No API keys and no APP_KEY: it starts with nothing to configure
  • DB_HOST, DB_NAME, DB_USER and DB_PASSWORD: Light Cloud sets them on deploy; set DB_SSLMODE=disable for a local database without TLS

About

config/database.php builds Laravel's pgsql connection from DB_HOST, DB_NAME, DB_USER, DB_PASSWORD and DB_SSLMODE, and the API only uses the api middleware group, so nothing is encrypted and no APP_KEY is needed until you add web routes or Crypt calls. The first change is usually renaming Item or giving it your own fields: add a migration, update the model and ItemController, and the container applies the migration on the next deploy. Each start runs php artisan migrate --force before Apache, so an unreachable database stops the app from starting; if two instances start together on a new migration, both can try it and one fails, then restarts and finds nothing left to migrate. There is no authentication or rate limiting, so every endpoint is open to anyone with the URL until you add tokens, for example with Laravel Sanctum. Unlike the Rails version it serves no OpenAPI document, matching the Flask and Express APIs.

FAQ

How do I connect Laravel to PostgreSQL with DB_HOST and DB_NAME?

config/database.php reads DB_HOST (with an optional :port), DB_NAME, DB_USER, DB_PASSWORD and DB_SSLMODE and builds Laravel's pgsql connection from them. DB_SSLMODE=require turns on TLS without checking the certificate.

Does a Laravel API need an APP_KEY?

Not this one. It only uses the api middleware group, which has no sessions or encrypted cookies, so nothing is encrypted. Add APP_KEY if you add web routes or Crypt calls.

How do I add a new resource to this Laravel API?

Add a migration, a model and a controller modelled on ItemController, then its routes in routes/api.php. Run php artisan migrate locally; the container applies it on the next deploy.

Does this Laravel API have Swagger or OpenAPI docs?

No. It is plain JSON. Packages such as dedoc/scramble generate an OpenAPI document and a docs page from the routes and controllers.

Can I host this Laravel API without Light Cloud?

Yes. Any Docker host builds the Dockerfile as it is, and any PHP 8.3+ web server pointed at public/ runs it after composer install --no-dev and php artisan migrate --force, with the DB_* variables set.

Price
Free
Framework
Laravel · PHP
Updated