This will remain as a template to start a new Laravel project.
- Development Environment
- Access URL
- Code Standard
- Static Analysis
- Testing
- CLI Helpers
- Supporting Links
Docker containers have been prepared for the local development purpose which includes all the required development environment dependencies. To start working on the API, you must have Docker installed in your local machine.
Laravel Sail is used as a command-line interface to interact with the default Docker development environment. Sail has been installed and configured for the API. When working with fresh clone of the API, use the following command to install Sail along with other composer dependencies. Once Sail is installed, you can follow the Sail documentation to start your Docker containers for the Laravel Template.
docker run --rm -v $(pwd):/var/www/html raazpuspa/larasail:8.2 composer install
By default, Sail commands are invoked using the vendor/bin/sail
script:
vendor/bin/sail up
However, instead of repeatedly typing vendor/bin/sail
to execute Sail commands, you may wish to configure a shell alias that allows you to execute Sail's commands more easily:
alias sail='[ -f sail ] && sh sail || sh vendor/bin/sail'
Once you start the project, you can access the Laravel logs in the following path:
http://localhost:9000/log-viewer
Note: The route path for log-viewer is configured via LOG_VIEWER_PREFIX
environment variable.
For already running/served application, you can access the Laravel Telescope at the following path:
http://localhost:9000/telescope
Note: The route path for Laravel telescope is configured via TELESCOPE_PATH
environment variable.
Mailpit has been configured with docker container. It is an email testing tool for developers. It acts as both an SMTP server, and provides a web interface to view all captured emails. To access mailpit inbox, check the following URL:
http://localhost:9002
Note: Laravel telescope is only available in local
app environment.
Note: The port will be as defined in .env
via FORWARD_APP_PORT
variable.
Note: The mailpit UI port will be as defined in .env
via FORWARD_MAIL_PORT
variable.
We follow the PSR-12 coding standard and the PSR-4 autoloading standard.
Compiled languages need to know about the type of every variable, return type of every method, etc. before the program runs. This is why the compiler needs to make sure that the program is “correct” and will happily point out to you these kinds of mistakes in the source code, like calling an undefined method or passing a wrong number of arguments to a function. The compiler acts as a first line of defense before you are able to deploy the application into production.
On the other hand, PHP is nothing like that. If you make a mistake, the program will crash when the line of code with the mistake is executed. When testing a PHP application, whether manually or automatically, developers spend a lot of their time discovering mistakes that would not even compile in other languages, leaving less time for testing actual business logic. Source
To make sure we do not leave any broken code that could have been caught by any compiler in supported language, we have configured PHPStan. PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of the code can be checked before you run the actual line.
On top of the PHPStan, Laravel Template uses Larastan, which extends PHPStan to support APIs provided by the Laravel framework by adding static typing to Laravel.
PHPUnit with Pest plugin is used to facilitate Unit and Feature testing. Pre-configured Docker setup includes XDebug extension for test coverage. Test coverage of minimum 95% is required for all newly made changes.
During the development phase of Laravel Template, you need to make sure all of your changes meet defined standards and static analysis is not reporting any issues. To see the reporting result within your local development environment, the following commands might come handy:
- Run code linting (with Laravel Pint)
sail bin pint
- Run code linting tests
sail bin pint:test
- Run static analysis (with PHPStan)
sail bin phpstan analyse
- Run unit tests
sail bin pest --testsuite=Unit
- Run feature tests
sail bin pest --testsuite=Feature
- Run available tests (includes coverage)
sail bin pest --coverage
- Automatic PHPDoc generation for Laravel Facades
vendor/bin/sail artisan ide-helper:generate
- Automatic PHPDocs for models
vendor/bin/sail artisan ide-helper:models -M
- PhpStorm Meta for Container instances
vendor/bin/sail artisan ide-helper:meta
Note: IDE helper commands are configured to run automatically whenever required. You may not require running them manually.
If your development environment is configured with Laravel Sail, replace php artisan
with vendor/bin/sail artisan
.