3

Is it possible to run Artisan commands from a script that is not part of Laravel?

How can I import artisan into my script?

<?php

 Artisan::call('some:command');

This script will is not part of Laravel and just a regular old php file. My question is, how can I import Artisan into my script?

My final goal, is to automate the installation of my app, I need to run a migrations, seeds and a couple other things.

Crysfel
  • 7,926
  • 3
  • 33
  • 41
  • I think you'd be better off using a bash script. The set up for that to work will probably be larger than setting up the Laravel project – DevK Apr 25 '18 at 23:42
  • You can always just create an instance of the command and call the `handle` method yourself, so long as the necessary dependencies are installed. Including an `autoload.php` file in the command would probably get you close though. – Brian Lee Apr 26 '18 at 03:34
  • @devk, how can we write php artisan down command in bash script which is not part of laravel command? – Trupti May 24 '19 at 07:22

1 Answers1

3

Unfortunately, you cannot use artisan without Laravel as it is not a stand-alone package and requires the full Laravel framework.

However, Artisan is based on the Symfony Console package which can be added to your script as a stand-alone package, which is the closest you will get to Artisan without writing a custom bash script.

http://symfony.com/doc/current/components/console.html

Rob Fonseca
  • 3,671
  • 2
  • 17
  • 13