My favourite *nix aliases for Laravel development

Hi Folks, I have something interesting to talk about today, Well this comes directly from my day to day life. Working as a freelancer is quite challenging. Though we get to pick the projects we work on, sometimes things can easily go out of our hands if not planned properly, I'm planning to talk about project management another day, today I am going to show how I make use of bash aliases to speedup my day to day development activities, specifically Laravel projects.

PS: Each of theses aliases can be added to your ~/.bashrc_profile or ~/.profile or your ~/.zshrc file

alias pa="php artisan"

php artisan is like the `Abrakadabra` of wizardry. We use it all the time to create models, controllers, resources, requests, commands and foo and bar and baz and.... you get my point 👨‍💻. Some people alias it to art but I prefer pa. It is in my muscles now, I cannot get rid of it even if I wanted to. Saves a ton of time for me.

alias msf="php artisan migrate:fresh --seed"

msf is a crazy command you will use if you are like me, when doing rapid prototyping it's highly likely that you have to add a column or alter a column in a database table frequently in your dev environment. Rather than adding a series of migration files in the early stage of projects, I use msf extensively until I do the first release of the project. It helps me maintain a clean codebase for migrations.

alias pac="php artisan config:cache; php artisan cache:clear; php artisan config:clear; php artisan view:clear"

pac is another great command in development, Just like msf when doing early stage development it's highly likely that we'll be altering our config files. pac helps me to quickly clear all the cache files in my local environment.

alias cda="composer dump-autoload"

cda is a kills alias I use, I only use this in times of an error where laravel says it cannot find a *SeederTable. In local environment when we add new seeder files to database/seeds/ folder and run msf laravel throws an error.

Class UsersTableSeeders does not exist [ReflectionException]

When I get this error my hands automatically do the magic and does a cda. 👌

function log_clear {    DIRECTORY=storage/logs/    if [[ -d "$DIRECTORY" ]]; then        echo > storage/logs/laravel*.log    fi
alias ll='tail -f -n 450 storage/logs/laravel*.log | grep -i -E "^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" --color'

The above two aliases are by far my favourites. As the name suggests log_clear clears out all the log files for the current project. ll on the other hand does some regex magic to extract the most important part from the stack trace of your exception from the log files. tail command helps us to listen to the log and dynamically update the new values when an exception occurs in our app. Trust me you'll love this when you get used to it.

If you want to grab all of the above aliases you can copy my gist here.

Feel free to comment here if you have any questions or suggestions for some interesting aliases you use.

I'll see you in another post. Have a nice day :) 

Related articles

Signature Pad with Alpine.js

The post describes the implementation of signature pads with Alpine.js. It also discusses how to integrate it with laravel livewire.