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.
The handle method will be called when your command is executed.
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.
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.
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.
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With