0

Is it possible to execute command prompt from Laravel controller? If YES, then how can i execute a command and what is the best way to do this? If NO,is there any other way how i can do this?

5

3 Answers 3

1

I dont Know if I get it. Cant you use PHP system()? If I'm wrong please explain clearly

http://php.net/manual/en/function.system.php

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, that was my bad, you did not really post a followup question, removed my comment (and will remove this tomorrow so it's clean here, hehe).
0

If you only need to run artisan commands (e.g. migrating the database) you can easily do that from your controller:

Route::get('/foo', function () {
    $exitCode = Artisan::call('email:send', [
        'user' => 1, '--queue' => 'default'
    ]);

    //
});

Source: Laravel Docs

There are some packages available that give you a UI for calling Artisan commands, just search for "laravel artisan web".


If you need to execute other commands you should give us more information about what you're trying to do.

Comments

0

Not 100% sure what you mean with "command prompt" but you can execute commands directly from php with the exec function. This is often not a recommended approach though and I would suspect that it is possible that if you need to run exec there is a design issue in the application.

I would recommend that you consider other approaches to the problem and only use exec in very special conditions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.