Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.