Giter Club home page Giter Club logo

laravel-template's Introduction

Laravel Template

This will remain as a template to start a new Laravel project.

Table of Content

  1. Development Environment
  2. Access URL
    1. Log Viewer
    2. Laravel Telescope
    3. Mailpit Inbox
  3. Code Standard
  4. Static Analysis
  5. Testing
  6. CLI Helpers
    1. Pint
    2. PHPStan
    3. Tests
    4. IDE Helpers
  7. Supporting Links

Development Environment

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'

Access URL

Log Viewer

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.

Laravel Telescope

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 Inbox

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.

Code Standard

We follow the PSR-12 coding standard and the PSR-4 autoloading standard.

Static Analysis

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.

Testing

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.

CLI Helpers

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:

Linting

sail bin pint
  • Run code linting tests
sail bin pint:test

Static analyser

  • Run static analysis (with PHPStan)
sail bin phpstan analyse

Tests

  • 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

IDE Helpers

  • 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.

Laravel Sail usage

If your development environment is configured with Laravel Sail, replace php artisan with vendor/bin/sail artisan.

Supporting Links

laravel-template's People

Contributors

raazpuspa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.