This project is a base for developing an API using Laravel 11, but with the directory structure of Laravel 10. It includes a Docker development environment configured with Nginx, PHP-FPM, PostgreSQL, Mailpit, Mailhog, and Laravel Pint for code formatting. Feel free to change the database as well as the web server to test the endpoints.
- Set the husky to work automatically with the hooks: pre-commit, pre-push, and commit-msg.
- Basic API authentication with sanctum.
- Unit and feature testing.
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/yanbrasiliano/laravel-11-skeleton-api.git cd laravel-11-skeleton-api
-
Copy the example
.env
file and configure as needed:cp .env.example .env
-
Build and start the Docker containers:
docker-compose up --build -d
-
Install Composer dependencies:
Dependencies will be automatically installed during the Docker build process.
-
Run the migrations:
docker-compose exec app php artisan migrate
- App: Main container running PHP-FPM, supervised by Supervisor.
- Nginx: Web server serving the Laravel application.
- PostgreSQL: Database for the application.
- Mailpit: Tool for viewing emails sent by the application.
- Mailhog: Alternative tool for viewing emails.
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"
To run Pint manually:
docker-compose exec app ./vendor/bin/pint
This project uses Husky to manage Git hooks, ensuring that tests, Larastan, and Pint are run before commits. This helps maintain code quality and adherence to coding standards.
Husky is installed and configured automatically. Only run npm i
to install packages. However, if you need to install it manually, you can do so with the following steps:
-
Install Husky:
npm install husky --save-dev
-
Activate Git hooks:
npx husky install
To run Husky hooks manually:
npx husky run pre-commit
To run Larastan manually:
docker-compose exec skeleton-api ./vendor/bin/phpstan
-
Start the containers:
docker-compose up -d
-
Stop the containers:
docker-compose down
-
Access the app container:
docker-compose exec skeleton-api bash
-
View app container logs:
docker logs skeleton-api
This project is licensed under the MIT License. See the LICENSE
file for more details.
This project provides a solid foundation for developing APIs in Laravel 11 while maintaining the familiar structure of Laravel 10. Feel free to expand and modify as needed to meet your specific development needs.