Last active
February 10, 2019 01:32
-
-
Save cyberlightdev/3a9f1c63a38b84398c9cc5daeda3e835 to your computer and use it in GitHub Desktop.
Run Artisan commands from anywhere inside a Laravel Project Hierarchy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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