'Set Laravel version using SAIL

I am using this script to create a new Laravel project:

https://laravel.build/example

However, Laravel 9.* is installed by default.

How do I change the script to install Laravel 8 ?

I tried inserting versions these three places: "laravel new 'version'", "laravel new example 'version'" and "laravelsail/php81-composer:'version'"



Solution 1:[1]

Run this command to install an old version of Laravel

  1. composer create-project laravel/laravel name_projet 8.0
  2. composer self-update
  3. composer update --no-scripts

Solution 2:[2]

You can modify the script replacing the

laravel new example-app

by the command from @Yug

composer create-project laravel/laravel example-app 8.0

installing laravel/sail:

composer require laravel/sail

and change docker image to

laravelsail/php74-composer

In the end the final script will be like:

docker info > /dev/null 2>&1

# Ensure that Docker is running...
if [ $? -ne 0 ]; then
    echo "Docker is not running."

    exit 1
fi

docker run --rm \
    -v "$(pwd)":/opt \
    -w /opt \
    laravelsail/php74-composer:latest \
    bash -c "composer create-project laravel/laravel example-app  8.0 && cd example-app && composer require laravel/sail && php ./artisan sail:install --with=mysql,redis,meilisearch,mailhog,selenium "

cd example-app

CYAN='\033[0;36m'
LIGHT_CYAN='\033[1;36m'
WHITE='\033[1;37m'
NC='\033[0m'

echo ""

if sudo -n true 2>/dev/null; then
    sudo chown -R $USER: .
    echo -e "${WHITE}Get started with:${NC} cd example-app && ./vendor/bin/sail up"
else
    echo -e "${WHITE}Please provide your password so we can make some final adjustments to your application's permissions.${NC}"
    echo ""
    sudo chown -R $USER: .
    echo ""
    echo -e "${WHITE}Thank you! We hope you build something incredible. Dive in with:${NC} cd example-app && ./vendor/bin/sail up"
fi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yug Normand Ngangue
Solution 2 Tuxboy