The "art" shortcut for "php artisan" for Laravel Sail with zsh
I still prefer using Laravel Sail for managing docker instances while working on a laravel probject, but I find typing sail php artisan
a bit tedious. A common go-to is art
, but how can we make sure it uses sail
while working with a project that supports sail, or native php while it doesn't? Here's a a nice little zsh function I've been using.
Open up your ~/.zshrc
with your favorite editor and add the following:
art() {
if [[ -d "./vendor/bin" && -f "./vendor/bin/sail" ]]; then
./vendor/bin/sail artisan "$@"
else
php artisan "$@"
fi
}
Once this is installed, you can just run simply art
instead of sail php artisan
.