Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Artisan::call() to pass non-option arguments

Tags:

In the shell I can create a database migration (for example) like so:

./artisan migrate:make --table="mytable" mymigration 

Using Artisan::call() I can't work out how to pass a non-argument parameter ("mymigration" in this example). I have tried many variants of the code below:

Artisan::call('db:migrate', ['--table' => 'mytable', 'mymigration']) 

Anyone got any ideas? I have been using shell_exec('./artisan ...') in the meantime but I'm not happy with the approach.

like image 985
GuruBob Avatar asked Oct 02 '14 11:10

GuruBob


People also ask

Which method will be called when an artisan command is executed?

The handle method will be called when your command is executed.

What does php artisan optimize do?

php artisan optimize creates a compiled file of commonly used classes in other to reduce the amount of files that must be included on each request. After running the command, all commonly used classes are compiled and then saved to this file directory: bootstrap/cache/compiled.

What is tinker in Laravel?

Laravel Tinker allows you to interact with a database without creating the routes. Laravel tinker is used with a php artisan to create the objects or modify the data. The php artisan is a command-line interface that is available with a Laravel. Tinker is a command tool that works with a php artisan.

What is Artisan call Laravel?

Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.


2 Answers

Artisan::call('db:migrate', ['' => 'mymigration', '--table' => 'mytable']) should work.

Incidentally db:migrate isn't an artisan command out of the box. Are you sure this is correct?

like image 127
Bower Avatar answered Sep 26 '22 07:09

Bower


In laravel 5.1 , you set options with/without values when calling an Artisan command from your PHP code.

Artisan::call('your:commandname', ['--optionwithvalue' => 'youroptionvalue', '--optionwithoutvalue' => true]); 

in this case, inside your artisan command;

$this->option('optionwithvalue'); //returns 'youroptionvalue'  $this->option('optionwithoutvalue'); //returns true 
like image 34
İlter Kağan Öcal Avatar answered Sep 25 '22 07:09

İlter Kağan Öcal