Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Usage:
# l project-name -a
#
# Available options:
# -a Authentication scaffolding with tests
# -g Add Github remote
# -d Create a fresh MySQL database
# Laravel Zonda
function l {
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Create Laravel Projects fast."
echo "Flags:"
echo " - -a Create an auth scaffolding"
echo " - -d Create a MySQL database"
echo " - -g Add GitHub remote"
return
fi
if [ -z ${1+x} ]; then
echo "Required parameter {name} is not set."
return
fi
PROJECT=$1
echo "Creating new Laravel project: $PROJECT..."
web
~/.composer/vendor/bin/laravel new $PROJECT
cd $PROJECT
git init
git add .
git commit -m "Fresh Laravel installation"
sed -i '' "s/APP_URL=http\:\/\/localhost/APP_URL=http\:\/\/$PROJECT\.dev/g" .env
sed -i '' "s/DB_DATABASE=homestead/DB_DATABASE=$PROJECT/g" .env
sed -i '' "s/DB_USERNAME=homestead/DB_USERNAME=root/g" .env
sed -i '' "s/DB_PASSWORD=secret/DB_PASSWORD=/g" .env
sed 's/<env name="MAIL_DRIVER" value="array"\/>/<env name="MAIL_DRIVER" value="array"\/>, <env name="DB_CONNECTION" value="sqlite"\/>, <env name="DB_DATABASE" value=":memory:"\/>/g' phpunit.xml | tr ',' '\n' > phpunit2.xml
rm phpunit.xml
mv phpunit2.xml phpunit.xml
git add .
git commit -m "Updated phpunit to use sqlite database"
function authenticationScaffold {
php artisan make:auth
git add .
git commit -m "Authentication scaffolding"
composer require dczajkowski/auth-tests
php artisan make:auth-tests -as
git add .
git commit -m "Authentication tests"
}
function githubAddRemoteAndPush {
git remote add origin git@github.com:DCzajkowski/$PROJECT.git
git push -u origin master
}
function createDatabase {
brew services start mysql
mysql -u root -e "CREATE DATABASE $PROJECT;"
}
if [[ "${@#-a}" = "$@" ]] then else
authenticationScaffold
fi
if [[ "${@#-g}" = "$@" ]] then else
githubAddRemoteAndPush
fi
if [[ "${@#-d}" = "$@" ]] then else
createDatabase
fi
subl .
echo -e "\e[36mEverything done! Happy coding 😎"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment