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]);
Related
Once our Laravel app is deployed to hosting (AWS Elastic Beanstalk) it's impossible to run php artisan from the ssh command prompt. Every time results in the following error:
In Container.php line 879:
Target class [request] does not exist.
In Container.php line 877:
Class "request" does not exist
Even just running php artisan without any parameters results in the same error. Locally everything is fine.
Strangely AWS runs certain bash php artisan commands as part of postdeploy hooks which work fine during deployment (eg. artisan config:cache). They work fine, but even if I disable that bash script and try to run those commands manually via ssh after deploy, I get the same error. Very confusing.
It's as if there's something happening after deployment that's breaking php artisan.
We're running PHP 8.0.18 and Laravel 9.0.1. I've tried composer dump-autoload, but I still get the same error while that's running.
Where would be the right place to start looking for the cause of this error message?
I have an artisan command where I do a soap call.
So I use the SoapClient
use SoapClient;
When I test run my command from an url like this:
Route::get('test-command', function() {
Artisan::call('updateRegisterLogs');
});
Everything works great!
Now when I try to run it with artisan on my linux server to test the command to create a cronjob I get the following error:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'SoapClient' not found
The weird thing is I even get this error when I try a simple php artisan to see a list of all my commands.
Why does my artisan break from this? My code works fine but artisan doesn't.
The PHP version and also the CLI ini file could be different from the web one and when running command with artisan you are using the php cli.
Check with
php -r "echo phpinfo();"
If your php cli has soap enabled.
I'm using Laravel 5.3.0 and it's running on a local server with Manjaro. I access the project folder trough ssh and I'm also using artisan trough SSH.
Everything runs fine, I run the server trough terminal:
php artisan serve --host 192.168.0.10 --port 80
And can acess the project trough browser.
But when I run this command:
php artisan make:controller ContatoController
or
artisan make:controller ContatoController
Nothing happens, it get's stuck, no message error after minutes. No controller is created.
Does anyone know how to solve this?
Here's what happened:
I was running artisan server and after that (on the same terminal) I was running the make:controller command.
The solution was:
1- Open linux terminal, run artisan server;
2- Open another terminal (or split window if you'r using Terminator) and use all commands you want.
I am using shell_exec command to run my artisan commands in the background. But when I run shell_exec in production server.
The route code as follows
Route::get('/test/exec', function () {
echo shell_exec('php ../artisan migrate:status 2>&1; echo $?');
});
it throws me error as follows.
PHP Fatal error: Cannot redeclare class Illuminate\Support\Traits\Macroable in /var/www/production/bootstrap/cache/compiled.php on line 6109 255
But when I run the same command in my local I got the output.
Laravel versin - 5.1.46
php version - PHP 5.5.9
os version - ubuntu
14.04
These are same on both servers. Where things went wrong. Please, some one helps me with this.
For this error try to run the following commands:
php artisan clear-compiled
php artisan optimize
this should regenerate compiled.php file.
As for executing artisan commands from within your code there are better ways than using shell_exec - for example using Laravel build in support for programmatically executing commands
The error
% Cannot redeclare class %
also occurs when you inject a class that has the same name as the one you are actively editing/modifying.
In your case, please make sure that you have not injected a class with the name "Macroable" elsewhere. If you have, make sure that the namespace is unique.
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 :)