Laravel project

WARNING

Please make sure you have installed PHP 7.4.x and NOT PHP 8.x.x otherwise you will end up with Composer errors at the end of this installation and not the landing page for our vinyl shop!

Start a new project

Make a new Laravel project

Method 1: Specific Laravel version using composer create project

  • Go to the folder C:\sites_laravel and open Git Bash
  • Start a new project where vinyl_shop is the folder of your new project and specify the desired (major) version of Laravel:
    composer create-project --prefer-dist laravel/laravel vinyl_shop "7.*"

WARNINGS

  • Always use this first method for making a new Laravel project, as this course is (specifically) written for Laravel version 7
  • The method below will make a new project based on the latest Laravel version (currently this is version 8, released in September 2020).

Method 2: Latest Laravel version using the Laravel installer

  • Go to the folder C:\sites_laravel and open Git Bash
    • First, download and install the Laravel installer using Composer: composer global require laravel/installer

REMARK

The above command installs the Laravel installer globally, so you only have to do this once

  • Start a new project where vinyl_shop is the folder of your new project: laravel new vinyl_shop
  • Configure Homestead

    • Map the public folder of your new project to your Homestead environment by updating the file C:\vagrant\homestead\Homestead.yaml



     
     

    sites:
        - map: homestead.test
          to: /home/vagrant/code
        - map: vinyl_shop.test
          to: /home/vagrant/code/vinyl_shop/public
    
    1
    2
    3
    4
    5
    • Add the new test domain to your hosts file C:\Windows\System32\drivers\etc\hosts:
      192.168.10.10 vinyl_shop.test
    • (Re)start Homestead
      • If Vagrant is running, stop it with the command vagrant halt
      • Execute the command vagrant up --provision
      • Browse to the project via the URL http://vinyl_shop.test

    myProject home page

    Configure PhpStorm

    • Open this project in PhpStorm
    • Wait until the project is fully indexed! (See bottom right of editor)
      indexing project
    • Run npm install

    Laravel IDE helper

    • The Laravel IDE Helper Generator package generates a file (_ide_helper.php) that PhpStorm understands, so it can provide accurate autocompletion (for Laravel facades)
    • Open a (Git Bash) terminal inside your project folder C:\sites_laravel\vinyl_shop
    • Install the package with Composer: composer require --dev barryvdh/laravel-ide-helper:2.8.2
    • (Re)generate the helper file yourself: php artisan ide-helper:generate
      • Generation is based on the files in your project, so the helper file is always up-to-date

    TIP

    • Add some commands to package.json (line 9 and 10) because you need to run thess scripts on a regular basis








     
     


    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js",
        "ide-helper-facades": "php artisan clear-compiled && php artisan ide-helper:generate",
        "ide-helper-models": "php artisan ide-helper:models -N"
    },
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    Enable the Laravel plugin

    Enable Laravel Plugin

    REMARK

    You have to enable the Laravel plugin for every new project!

    • Restart PhpStorm

    Configure the (source) directories

    • Configure the following Directories in PhpStorm
      • If necessary: set app as Sources and prefix it with App\
      • Set public as Sources
      • Set public as Resource Root

    Enable directories Enable directories

    Update timezone

    • If you install a fresh Laravel and create your app, you may notice that all created_at and other timestamp fields in the database are being saved in UTC timezone
    • Open the Laravel project file config/app.php and look for this entry 'timezone' => 'UTC',
    • Change the default timezone (UTC) to your local timezone, i.e. Europe/Brussels











     

    /*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */
    
    'timezone' => 'Europe/Brussels',
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    Update an existing project (optional)

    • To update an existing project to the latest (backward compatible) Laravel version (for example the latest version of Laravel 7), use the command composer update in a (Git Bash) terminal within the project folder

    TIP

    To check the version of a Laravel project, open a (Git Bash) terminal inside the project folder and use the command php artisan --version

    Last Updated: 10/11/2021, 6:59:50 PM