I would like to execute the following command : composer update in my controller in laravel, however this one does not work.
On the other hand the command composer info works perfectly.
When I execute composer update in a command prompt all my dependencies are correctly updated in the laravel vendor file but when I try to execute composer update in my controller nothing happens.
here is my code :
$data['output'] = shell_exec( 'cd '. base_path() .' && composer update' );
dd($data);
and here is the result :
array:1 [▼
"output" => null
]
Could you help me to understand why composer update does not work in a controller ?
I would like to update my dependencies in a controller without the command prompt.
Thank you.
From the php docs for shell_exec():
The output from the executed command or NULL if an error occurred or the command produces no output.
Sounds like you'd be better off using passthru() instead as that will give you the erroneous output.
Speaking of erroneous, this is idea sounds like a recipe for unmitigated disaster.
Related
I've created a custom command functionality for my project, but there is something strange happening at the moment.
First i thought it might had something to do with the composer dump-autoload but after adding the exec command it still didn't work.
I do have the
seeds as autoload in my composer.json
$this->className = "MyDbSeeder"
$this->call('make:seeder', ['name' => $this->className]);
exec("composer dump-autoload");
sleep(5);
$this->call('db:seed', ['--class' => $this->className]);
/* Response */
// -- ReflectionException : Class MyDbSeeder does not exist --
/* But when i'm running the exactly same command but not through the `$this->call()` function it works perfectly fine. */
exec("php artisan db:seed --class {$this->className}", $output);
/* Response */
// -- "Database seeding completed successfully." --
Of course it does work with the exec command, but i don't feel like this is the solution that i need to deliver.
Anyone knows why the regular laravel command ain't working?
I have been creating web application using symfony, I want to run commande line instead of run URL inside browser.
composer.json:
"import-data": [
"curl http://localhost:8000/importusers?username=client1"
]
When I run : composer import-data it works fine,
but how I can pass client1 as an argument in this command.
thank you.
I got this error message when I tried to make an alias for artisan:
[Settings | Tools | Command Line Tool Support ] -> add -> tool based on Symfony Console
Problem
Failed to parse output as xml: Error on line 4: Content is not allowed in prolog..
Command
C:\xampp\php\php.exe C:\xampp\htdocs\laratest\artisan list --xml
Output
[Symfony\Component\Console\Exception\RuntimeException]
The "--xml" option does not exist.
Ok, I know, what's the problem but I don't find any solution for this.
Thank you for the tips!
A temporal modification of the "artisan" file under the Laravel folder will do the trick. (Working on PhpStorm 10.0.3)
if( isset($argv[1]) && $argv[1] == 'list' &&
isset($argv[2]) && $argv[2] == '--xml' ) {
$argv[2] = '--format=xml';
$_SERVER['argv'] = $argv;
}
require __DIR__.'/bootstrap/autoload.php';
Now you can add the "artisan" command line tool support based on Symfony and remove the lines if you wish to.
For everybody affected, this is the commit which removed support for –xml: https://github.com/symfony/console/commit/6d6d9031b9148fed0e2aacb98ac23ce6168ba7ac
Just revert changes in ListCommand.php
it work in 2.7 version
There is no --xml option, you are getting this error when you running this command:
The "--xml" option does not exist.
So what you should do in this case is running:
php artisan help list
and you will get list of all available parameters
and now you will know you need to use:
php artisan list --format=xml
instead of:
php artisan list --xml
EDIT
I've verified it in PhpStorm 10.0.3
as Tool path you can paste in your case:
C:\xampp\php\php.exe C:\xampp\htdocs\laratest\artisan list --format=xml
and it will work
Update composer before add command line tool:
composer update
I need to migrate my database schema for some unit tests I'm writing, and one of these migrations is included in a package. Normally, from the command line, I'd run this command:
php artisan migrate --package=tappleby/laravel-auth-token
And to run my own migrations in code I'd do:
Artisan::call('migrate');
However, I can't seem to get Artisan to run package migrations from inside code. I've tried this:
Artisan::call('migrate --package=tappleby/laravel-auth-token');
but that results in an unknown command error. I've also tried these:
Artisan::call('migrate', '--package=tappleby/laravel-auth-token');
Artisan::call('migrate', ['--package=tappleby/laravel-auth-token']);
Artisan::call('migrate', ['package=tappleby/laravel-auth-token']);
None of the above works. What's the correct way of running package migrations in my code?
I believe the correct syntax uses an associative array for the command parameters, where the item key is the name of the parameter and the item value is the value of the parameter. This should work in your case:
Artisan::call('migrate', ['--package' => 'tappleby/laravel-auth-token']);
I did it with --path:
Artisan::call('migrate', ['--path' => 'vendor/systeminc/laravel-admin/src/database/migrations']);
I just created a custom class that will do more commands. This command will be launched by a robot in the future.
But when I do a
$command_fixtures_load = $this->getApplication()->find('doctrine:fixtures:load');
$arguments_fixtures_load = array(
'command' => 'doctrine:fixtures:load',
'--fixtures' => "src/XXX/XXXBundle/Tests/DataFixtures"
);
$input_fixtures_load = new ArrayInput($arguments_fixtures_load);
$command_fixtures_load->run($input_fixtures_load, $output);
I have this :
Careful, database will be purged. Do you want to continue Y/N ?
So the script waits for an answer, or I would give no answer but it makes the load Fixtures fully automatic.
How?
Running
php app/console doctrine:fixtures:load --no-interaction
Will purge your database without asking the question.
To see more options run
php app/console doctrine:fixtures:load --help