Brendan White
Brendan White

Reputation: 453

Can I run eg artisan commands without having to type php

OK, so I realise this is a bit lazy. :-) But I'd like to be able to run Artisan commands without having to type the "php" part. So just artisan migrate instead of php artisan migrate for example.

Is it possible to "install" artisan like this? Or do I just have to live with typing the four extra characters?

PS - yes, I know I just typed hundreds of characters to ask how to save typing four characters. :-) But I only have to ask once ... and if someone has an answer, I can save typing four characters hundreds of times.

My main dev box is a Mac with El Capitan 10.11.6, but I also use Ubuntu and RedHat in VMs, test servers, etc.

Upvotes: 1

Views: 1233

Answers (2)

Alexey Mezenin
Alexey Mezenin

Reputation: 163808

On Mac you can create bash aliases. Edit ~/.bash-profile hidden file which is in your user's directory. In case if you're using zsh then edit ~/.zshrc file.

Here's my file which creates couple of aliases:

alias composer="php /usr/local/bin/composer.phar"
alias a="php artisan"
alias am="php artisan migrate:refresh --seed"
export PATH=$PATH:~/.composer/vendor/bin

So, when I run a make:model, it runs php artisan make:model. When I enter am command, artisan refreshes all migrations and seeds the data.

Upvotes: 3

user5520186
user5520186

Reputation:

You also could use a "Shebang" line instead of creating aliases. Just place the path to your php interpreter on top of your artisan file.

#!/usr/local/bin/php
<?php

// ...

Now you can call the artisan file directly and the correct interpreter will be loaded.

Maybe you have to add execution permissions to your artisan file.

chmod +x ./artisan

Upvotes: 3

Related Questions