DEV Community

Eddie Goldman
Eddie Goldman

Posted on

How to Replace “php artisan” With a Short Command in Windows PowerShell

Why I Wanted a Shorter Laravel Command

If you use Laravel every day, you type the same command again and again:

php artisan ...
Enter fullscreen mode Exit fullscreen mode

For example:

php artisan optimize
php artisan migrate
php artisan make:model User
Enter fullscreen mode Exit fullscreen mode

After typing this dozens of times per day, it becomes slow and annoying.
So I decided to make my workflow faster. My goal was simple:

Use just one letter — “a” — instead of “php artisan”.


Why a Normal Alias Does Not Work in Windows PowerShell

Windows PowerShell does not support this kind of alias correctly.
If you try to create a simple alias, you will see errors like:

Could not open input file: optimize
Enter fullscreen mode Exit fullscreen mode

This happens because PowerShell incorrectly runs:

php optimize
Enter fullscreen mode Exit fullscreen mode

instead of:

php artisan optimize
Enter fullscreen mode Exit fullscreen mode

To fix this, we need a function that sends all arguments directly to php artisan.


Step-by-Step: Create the “a” Command in PowerShell

Follow these steps to make your custom a command work everywhere.


1. Open PowerShell

Press Start → PowerShell.


2. Check Your Profile File Path

Run:

echo $PROFILE
Enter fullscreen mode Exit fullscreen mode

You will see something like:

C:\Users\YourName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Enter fullscreen mode Exit fullscreen mode

3. Open the Profile File

Run:

notepad $PROFILE
Enter fullscreen mode Exit fullscreen mode

If the file does not exist, choose Yes to create it.


4. Add This Function Inside the File

This is the correct function that makes a work exactly like php artisan:

function a {
    & php .\artisan @args
}
Enter fullscreen mode Exit fullscreen mode

This line:

  • runs php artisan
  • passes all arguments to it (@args)
  • works in any Laravel project folder
  • supports all Artisan commands normally

Save the file and close Notepad.


5. Reload the Profile

Run:

. $PROFILE
Enter fullscreen mode Exit fullscreen mode

(important: dot, space, then $PROFILE)

Your new command is now active.


How to Use the New “a” Command

Now you can replace anything like this:

php artisan optimize
Enter fullscreen mode Exit fullscreen mode

with:

a optimize
Enter fullscreen mode Exit fullscreen mode

More examples:

a migrate
a tinker
a config:cache
a make:model Product
a make:controller Admin/DashboardController
Enter fullscreen mode Exit fullscreen mode

It behaves 100% the same as:

php artisan ...
Enter fullscreen mode Exit fullscreen mode

but much faster to type.


Why This Saves Time

If you run multiple Artisan commands during development, this simple shortcut:

  • saves keystrokes
  • speeds up your workflow
  • makes repetitive tasks easier
  • keeps your hands on the keyboard
  • reduces typing effort

It takes less than one minute to set up but improves your daily coding speed immediately.

See my blog post: https://eddie-goldman.com/how-to-replace-php-artisan-with-a-short-command-in-windows-powershell/

Top comments (0)