Skip to content

Instantly share code, notes, and snippets.

@cyberlightdev
Last active February 10, 2019 01:32
Show Gist options
  • Save cyberlightdev/3a9f1c63a38b84398c9cc5daeda3e835 to your computer and use it in GitHub Desktop.
Save cyberlightdev/3a9f1c63a38b84398c9cc5daeda3e835 to your computer and use it in GitHub Desktop.
Run Artisan commands from anywhere inside a Laravel Project Hierarchy.
#! /bin/bash
# NOTE: Artisan commands are run relative to the actual location of the `artisan` file, regardless of your Working Directory. This
# should have a negligible affect on functionality.
function artisan() {
CURRENT=`pwd`
FAIL=true
#This assumes all the laravel project(s) are located somewhere within your home directory (i.e. /Users/JefferyWay/Code/Project)
# Change out the $HOME variable as needed to represent project(s) root, or just use /
while [ `pwd` != "$HOME" ]
do
if [ -f artisan ]; then
php artisan "$@"
FAIL=false
break;
else
cd ..
fi
done
cd $CURRENT
if $FAIL ; then
>&2 echo "No artisan command found. Are you in a Laravel Project?"
return 1
fi
}
#This is not required, but demonstrates the use of the global artisan function (while also making a handy alias for tinker)
alias tinker="artisan tinker"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment