I want to create the commands order:process and order:lock. So far, I have figured out that I need to run php artisan command:make process --namespace=order to create the order:process class file. Then I need to set the $name value in the app/commands/process.php to 'order:process'. This is where I'm stuck.
I think I need to add something to app/start/artisan.php to make the command usable, but I can't figure out what. I've tried Artisan::add(new order\process); and Artisan::add(new process);, but neither of these work. What do I need to do, to get my new commands available to be run from the command line? I know the problem is to do with the use of a namespace, but I can't find any documentation on artisan commands that use namespaces.
For laravel 5.0
php artisan make:console Foo --command=foo:do
Edit your commands located in app/Console/Commands/Foo.php
Then register your commands by adding an entry to app/Console/Kernel.php
protected $commands = [
'Cloudlite\Console\Commands\Inspire',
'Cloudlite\Console\Commands\EmailParser',
'Cloudlite\Console\Commands\Foo',
];
You can now run like the following (example default option, edit Foo.php)
php artisan foo:do example=1
First create them with artisan command
php artisan command:make OrderProcessCommand --command=order:process
php artisan command:make OrderLockCommand --command=order:lock
Edit your commands located in app/commands
Then register your commands in app/start/artisan.php
Artisan::add(new OrderProcessCommand);
Artisan::add(new OrderLockCommand);
I still have no idea how to use namespaces, but I have figured this part out.
The answer is, to use php artisan command:make orderProcessCommand, and register that with Artisan::add(new orderProcessCommand);. The in orderProcessCommand.php, set the $name to order:process. Artisan will read the class as directed by the registration command, but make it available to be called as described in the $name field.
Related
I have run the following Laravel command PHP artisan make: migration add_category_id_to_posts but I need to run the following command as well PHP artisan make: migration add_category_id_to_posts --table=posts then I need to roll back the first command and run the second command. then How?
As mentioned by Fatima Mazhit, this command cannot be rolled back.
Simply delete the newly created add_category_id_to_posts migration file and run php artisan make:migration add_category_id_to_posts --table=posts.
You need to delete the earlier created migration manually and run the same command again after making appropriate changes in your migration. Or simply run php artisan migrate:rollback, will do your task.
go to your database/migration/your migration
delete the migration you recently created, and then run the command again like so:
php artisan make:migration add_category_id_to_posts --table=posts.
note: you can rollback your migrations if you migrate your migrations on the command : php artisan migrate then you can rollback by php artisan migrate:rollback
when you use comand by example:
php artisan make:migration create_tasks_table --create=tasks
it creates a table file and dependency link inside of file
\vendor\composer\autoload_classmap.php
How I can do something like?
php artisan remove:table:file create_Task_table
No such command exists in artisan console. However, you can either make one such command or just delete the migration and execute the following command in the console.
composer dump-autoload
I am trying to execute some custom artisan command from controller like
Artisan::call('php artisan MyCustomCommand');
but it works fine when I execute
php artisan MuCustomCommand from CLI.
I have registered command in app/start/artisan.php.
Even Artisan::call('php artisan --help'); is not working.
You should run artisan command like this from your controller .
Example :
Artisan::call('migrate:install');
So Instead of doing Artisan::call('php artisan MyCustomCommand');
You should do
Artisan::call('MyCustomCommand');
Here is the documentation
Hope it helps :)
I just started using and watched a youtube video how to start.
I try to make my first controller, so I execute this command:
php artisan controller:make WelcomeController
I get an exception:
[InvalidArgumentException]
There are no commands defined in the "controller" namespace.
I am executing this in the root folder of the Laravel project.
The command is actually:
php artisan make:controller WelcomeController
You wrote controller:make instead of make:controller.
In the future you can run just php artisan and it will list all commands with a short description for each one, that way you can make sure you're running the correct command. If you want more details about a command, like usage and what options it accepts, you can run php artisan help [command]. So for your command it would be:
php artisan help make:controller
Just like in title. I'm trying to run from artisan
php artisan command:make NameOfCommand
but all I see is
There are no commands defined in the "command" namespace.
Any idea what is this?
As the documentation says (Current version is 5.2 at this moment):
Once your command is finished, you need to register it with Artisan so
it will be available for use. This is done within the
app/Console/Kernel.php file.
in the Kernel.php file you must add:
protected $commands = [
Commands\NameOfCommand::class
];
(ref: https://laravel.com/docs/5.2/artisan#registering-commands)
You have misplaced the command it is
php artisan make:command NameOfCommand
and not
php artisan command:make NameOfCommand
If you have simply write php artisan within your command prompt it'll show you the list of commands over there have a look
In laravel 5.2 use php artisan make:console NameOfCommand