Laravel/Vue 2 Starter (Backend)

This template is designed for a quick start of a new Laravel/Vue project.

The starter is decoupled into two parts:

Features and Dependencies

System Requirements

  • PHP >= 8.0.2
  • PHP Extensions: BCMath, Ctype, Fileinfo, JSON, Mbstring, OpenSSL, PDO, Tokenizer, XML, cURL, GD, Imagick
  • Composer >= 1.9.x

Project Setup

  1. Clone the repository

    git clone https://github.com/slava-arapov/starter-laravel-vue-backend.git
    cd starter-laravel-vue-backend
  2. Copy your .env file for local development or production. Laravel Sail parameters are used by default

    cp .env.example .env
  3. Edit your .env file. Make sure to set these variables

    APP_URL=http://localhost # local development
    APP_URL=https://api.yourappname.com # production
    
    DB_HOST=mysql # docker-compose, Laravel Sail environment
    DB_HOST=127.0.0.1 # local development and production
    DB_HOST=localhost # if you get an PDOException error
    
    DB_USERNAME=user
    DB_PASSWORD=password
    
    MEMCACHED_HOST=memcached # docker-compose, Laravel Sail environment
    MEMCACHED_HOST=127.0.0.1 # local development and production
    
    REDIS_HOST=redis # docker-compose, Laravel Sail environment
    REDIS_HOST=127.0.0.1 # local development and production
    
    MAIL_FROM_ADDRESS=mail@yourappname.com
    
    # Some Sanctum specific variables ↓
    SANCTUM_STATEFUL_DOMAINS=localhost:5173 # local development
    SANCTUM_STATEFUL_DOMAINS=yourappname.com # production
    
    SPA_URL=http://localhost:5173 # local development
    SPA_URL=https://yourappname.com # production
    
    SESSION_DOMAIN=localhost # local development
    SESSION_DOMAIN=.yourappname.com # production
  4. Set your default admin credentials in database\seeders\DatabaseSeeder.php

  5. Configure a bash alias for Laravel Sail in .bashrc file

    alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'
  6. Change the image name for the laravel.test service in your application's docker-compose.yml file

  7. Start Docker containers in background

    sail up -d
  8. Install dependencies and run some required commands

    sail composer install
    sail artisan key:generate # to set APP_KEY value for encrypting and decrypting
    sail artisan storage:link # to use public storage disk
    sail artisan migrate --seed # to run migrations and seed admin user
    
    # OR
    composer install
    php artisan key:generate
    php artisan storage:link
    php artisan migrate --seed

Run

sail up -d

Now you can browse the site at http://localhost

Stop

sail stop

Static Code Analysis Tools

You can run some tools

# PHPStan/Larastan
sail composer phpstan

# Psalm
sail composer psalm

# PHP Coding Standards Fixer (dry run)
sail composer php-cs-fixer-validate

# PHP Coding Standards Fixer (fix)
sail composer php-cs-fixer

# Rector (dry run)
sail composer rector-validate

# Rector (fix)
sail composer rector

You can customize scripts in composer.json and rules in phpstan.neon, psalm.xml, .php-cs-fixer.php config files.

Credits

This starter is designed using the instructions at https://laravelvuespa.com. I highly recommend to check out this resource and to support @garethredfern.

License

This starter is open-sourced software licensed under the MIT license.