Replies: 2 comments
-
@crynobone by the way this is an issue, not a discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is not an issue, you must reuse the same output buffer to have the prompts working. Not even if I use the code that you've given in a command it doesn't work: <?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Console\Output\BufferedOutput;
class test2Command extends Command
{
protected $signature = 'test2';
protected $description = 'Command description';
public function handle(): void
{
$outputBuffer = new BufferedOutput();
// Run the user:create command
Artisan::call(command: 'test', outputBuffer: $outputBuffer);
echo $outputBuffer->fetch();
}
} <?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use function Laravel\Prompts\password;
use function Laravel\Prompts\text;
class TestCommand extends Command
{
protected $signature = 'test';
protected $description = 'Command description';
public function handle(): void
{
$name = text('Enter your name:');
$email = text('Enter your email:');
$password = password('Enter your password:');
}
} This works if I switch the output to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
10.48.10
PHP Version
8.2.15
Database Driver & Version
MySQL Community Server 8.4.0
Description
I'm encountering challenges while attempting to execute interactive Artisan commands directly from Laravel migrations. The issue arises due to the absence of support for interactive input within migration files.
Steps To Reproduce
Problem:
When trying to run an interactive Artisan command, such as
user:create
, from within a migration, the process stalls as it waits for user input. This results in a blinking cursor, indicating the command is awaiting input, but without any prompts visible.My migration file
RunUserCreateCommand
:Here an example of
UserCommand.php
:Expected Outcome:
Ideally, the
user:create
command should execute seamlessly within the migration, prompting the user for input and proceeding accordingly.Seeking Solutions:
I'm exploring ways to overcome this obstacle and execute interactive Artisan commands within Laravel migrations. Any insights or alternative approaches to accomplish this task would be greatly appreciated. Thank you!
PS:
Interestingly, when using the same Artisan command within a seeder, interaction works seamlessly. For instance, running
Artisan::call(command: 'user:create', outputBuffer: $this->command->getOutput())
in a seeder executes the command while allowing interaction. This stark difference in behavior prompts further investigation into why interactive commands behave differently within migrations. Any insights or suggestions on this matter are welcome.Beta Was this translation helpful? Give feedback.
All reactions