July 10, 2024
Bash aliases are a great way to speed up your workflow. They allow you to create custom commands that can be used to perform common tasks quickly and easily.
Aliases are custom commands that you can create to perform common tasks. For example, you can create an alias to run your tests, migrate your database, or clear your cache.
To create an alias, open your the ~/.bash_aliases or the ~/.bashrc file and add the following line:
1alias pa="php artisan"
Be sure to source the file after adding the alias by running the following command:
1source ~/.bash_aliases23.. or source ~/.bashrc
Now you can run the pa command in your terminal to run any php artisan command. For example, you can run pa migrate to migrate your database.
I thought it would be fun to share some of the aliases I use in my Laravel projects and also source some from the community.
Here are my personal aliases that I use in my projects:
1alias pa="php artisan" 2 3alias tp="php artisan test -p" 4 5alias mfs="php artisan migrate:fresh --seed" 6 7alias c="composer" 8 9alias cu="c update"1011alias ci="c install"1213alias gpo="git pull origin"1415alias nah="git reset --hard;git clean -df"1617alias t="phpunit"1819alias tf="phpunit --filter"
Dries Vints is a Software Engineer at Laravel and has some great aliases that he uses in his projects. I found the cfresh alias to be particularly interesting for nuking your vendor directory and composer.lock file. Here are a few of my favorites:
1alias a="herd php artisan" 2 3alias tinker="herd php artisan tinker" 4 5alias seed="herd php artisan db:seed" 6 7alias serve="herd php artisan serve" 8 9alias cfresh="rm -rf vendor/ composer.lock && composer i"1011alias wip="commit wip"1213alias commit="git add . && git commit -m"
You can find more of Dries' aliases in his aliases.zsh file from the driesvints/dotfiles repository.
Freek Van der Herten is a developer at Spatie, which is a company that has created hundreds of Laravel packages. You will likely have used one of their packages in your projects. Here are a few interesting aliases:
1alias a="php artisan" 2 3alias cda="composer dump-autoload -o" 4 5alias larastan="vendor/bin/phpstan analyse" 6 7alias deploy='envoy run deploy' 8 9alias pp="php artisan test --parallel"1011alias sail='./vendor/bin/sail'1213alias glog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
You can find more of Freek's aliases in his .aliases file in the freekmurze/dotfiles repository.
Jess Archer is a developer at Laravel and has some great aliases that she uses in her projects. There are some interesting ones in here such as the laravel-setup alias. Here are a few of my favorites:
1alias artisan="php artisan" 2 3alias tinker="artisan tinker" 4 5alias sqlit="sed -e 's/\(DB_.*\)/# \\1/g' -e 's/# \(DB_CONNECTION=\).*/\\1sqlite/g' -i .env" 6 7alias lenv="cp -n .env.example .env && (grep '^APP_KEY=.\+' .env > /dev/null || artisan key:generate)" 8 9alias laravel-setup="composer install && lenv && sqlit && artisan migrate --force --seed"1011alias sail='[ -f sail ] && sail || vendor/bin/sail'
You can find more of her aliases in her zshrc file within the jessarcher/dotfiles repository.
Christoph Rumpel is a developer and content creator who has some great aliases that he uses in his projects. I found the clearlogs alias to be particularly useful for deleting your log files. Here are a few of my favorites:
1alias art='php artisan'23alias clearlog='truncate -s 0 $PWD/storage/logs/laravel.log'45alias clearlogs='truncate -s 0 $PWD/storage/logs/*.log'67alias nope="git reset --hard && git clean -df"
You can find more of his aliases in his aliases.zsh file within the christophrumpel/dotfiles repository.
Steve McDougall is a developer and content creator who has some great aliases that he uses in his projects. I found the sail commands useful for dealing with projects using Sail. Here are a few of my favorites:
1alias a="php artisan"23alias sail='[ -f sail ] && sh sail || sh vendor/bin/sail'45alias sa='sail artisan'67alias test='a test'89alias sail-test 'sail artisan test
You can find more of his aliases in his aliases.zsh file within the JustSteveKing/dotfiles-mac repository.
If you're looking for more aliases, you can search the GitHub search results for aliases specific to Laravel. Typically, you will find these within dotfiles repositories.
If you have any useful aliases that you would like to share that didn't make this list, feel free to reach out to me on X/Twitter.