Running Artisan Command from laravel 4.2 Controller - php

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 :)

Related

how to roll back Laravel command

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

Error while running artisan command from controller

while running below artisan command from controller works fine
Artisan::call('backup:run');
but why this is not working
Artisan::call('backup:run --only-db');
it throws error The command "backup:run --only-db" does not exist.
through CLI it works fine
php artisan backup:db --only-db
I believe what you wanted to do is.
Artisan::call('backup:run',['--only-db'=>true]);

How do I remove old artisan command from Kernel in Laravel 5

I have created some Command files into my Laravel Application. Laravel version is 5.2. I set command like: get:email in the Command file. Also call the Command file into Kernel.php. After that I can see the artisan command list by typing the command php artisan list. as like as below:
//output
get:email
And I changed the command title get:email to get-bq:email. When I run the command php artisan get-bq:email -- its working nicely. Also I can see the list by typing the command php artisan list::
//output
get-bq:email
Issue / Problem: Both commands are working. But I won't to work with both of them. I have done the following things:
modified command file as well as command
run composer dump-autoload -o
run composer update
remove vendor and storage folder then run composer update again.
Still the old command is working into my system.
What I want: How May I remove my old commands from my Laravel(5.2) application?
Run these commands:
php artisan cache:clear
php artisan config:clear
These commands will clear app cache and config cache and recreate it.
I've had the same problem recently.
Repoeatedly tried
php artisan cache:clear
php artisan config:clear
and the cached Kernal command wouldn't clear.
In desperation i killed the queue worker terminal and restarted the queue with the command
php artisan queue:work
The issue stopped.

Trouble creating my first Laravel controller

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

"There are no commands defined in the 'command' namespace." after running command:make in Laravel

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

Categories