-
Notifications
You must be signed in to change notification settings - Fork 96
Installation
The simplest way to get started is to execute the following composer command:
composer create-project --prefer-dist specialtactics/laravel-api-boilerplate
Alternative, you can also click the Use this template button on the main github page of this project, to create a clean repo (ie. not a fork) with this template.
You can (and should) set this up in exactly the same way as laravel. The minimal installation steps for local development are outlined below, and you should consult the Laravel documentation for comprehensive Laravel configuration options.
Note that this boilerplate does not support Lumen.
Assuming composer is already installed, when setting up the project for the first time - if you did not use the "create-project" command, please execute the following commands:
php artisan key:generate
php artisan jwt:secret
php artisan ide-helper:generate
php artisan ide-helper:meta
This boilerplate adds several additional configuration files you should be aware of;
- api.php - Dingo API Configuration
- jwt.php - Tymon JWT Configuration
- stubs.php - This loads custom API stubs for certain artisan generators
It is not necessary to modify them during installation, but you should familiarise yourself with them - just in case you need to change some relevant configurations later.
This project comes with a default minimalist docker setup based on laradock. It is entirely optional, but you will find it beneficial to use it. If you do not already have it, install the latest version of docker and docker-compose - for detailed instructions, please go to https://docs.docker.com/install/
If you are running anything on port 80 locally, you will want to stop that first. Make sure you have copied the .env.example to .env
PostgreSQL is recommended due to several features which make it better for API development, such as a native binary-backed UUID type and native JSON type, but you can swap it out for a MySQL or other DB container if you wish.
- It is recommended that you rename "your_project" to the name of your project, inside:
- docker-compose.yml
- .env
- You can change the cache driver (in the .env) to redis if you wish.
Get everything going by using the command docker-compose up
, and you should be able to access the project through http://localhost
. You can access the workspace using the script ./env/workspace.sh
- which just SSHes into the workspace container. Inside that, you can run all the composer, artisan and any other commands for the project.
- You can add ports to the PostgreSQL container if you wanted to access the DB from your computer
ports: - ${POSTGRES_PORT}:5432
You have two options in terms of how to deal with CORS. You should choose one, depending on what you prefer.
You can add the CORS header configuration to your apache/nginx config for this project. There are example apache and nginx vhost/site files in this project's docs directory which demonstrate how to do this.
Add and install the following package once you are set up:
It will handle CORS for you.