16

I'm using Artisan::call('migrate'); in a Laravel controller method and it working while Laravel version was 4.1. After updating Laravel using composer update command (and setting "laravel/framework": "4.2.*" in composer.js) this controller method (as this is the only command in it) doesn't work anymore.

I've even added 'cipher' => MCRYPT_RIJNDAEL_256 in /app/config/app.php as stated in http://laravel.com/docs/upgrade#upgrade-4.2

That already happens: http://laravel.io/forum/06-02-2014-not-able-run-artisan-commands

When I put Artisan::call('migrate') into try/catch block controller looks like this:

public function ArtMigr(){
    try {
            Artisan::call('migrate');
        } catch (Exception $e) {
            echo $e;
        }   

}

And I'm getting the following error:

exception 'ErrorException' with message 'Use of undefined constant STDIN - assumed 'STDIN'' in D:\htdocs\artisan_error\vendor\symfony\console\Symfony\Component\Console\Helper\QuestionHelper.php:112 Stack trace: #0 D:\htdocs\artisan_error\vendor\symfony\console\Symfony\Component\Console\Helper\QuestionHelper.php(112): Illuminate\Exception\Handler->handleError(8, 'Use of undefine...', 'D:\htdocs\artis...', 112, Array) #1 D:\htdocs\artisan_error\vendor\symfony\console\Symfony\Component\Console\Helper\QuestionHelper.php(49): Symfony\Component\Console\Helper\QuestionHelper->doAsk(Object(Symfony\Component\Console\Output\NullOutput), Object(Symfony\Component\Console\Question\ConfirmationQuestion)) #2 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\Command.php(186): Symfony\Component\Console\Helper\QuestionHelper->ask(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput), Object(Symfony\Component\Console\Question\ConfirmationQuestion)) #3 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\ConfirmableTrait.php(21): Illuminate\Console\Command->confirm('Do you really w...') #4 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Database\Console\Migrations\MigrateCommand.php(59): Illuminate\Database\Console\Migrations\MigrateCommand->confirmToProceed()

5 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\Command.php(112):

Illuminate\Database\Console\Migrations\MigrateCommand->fire() #6 D:\htdocs\artisan_error\vendor\symfony\console\Symfony\Component\Console\Command\Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput)) #7 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\Command.php(100): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput)) #8 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Console\Application.php(96): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArrayInput), Object(Symfony\Component\Console\Output\NullOutput)) #9 [internal function]: Illuminate\Console\Application->call('migrate') #10 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Foundation\Artisan.php(57): call_user_func_array(Array, Array) #11 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(208): Illuminate\Foundation\Artisan->__call('call', Array) #12 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(208): Illuminate\Foundation\Artisan->call('migrate') #13 D:\htdocs\artisan_error\app\controllers\HomeController.php(160): Illuminate\Support\Facades\Facade::__callStatic('call', Array) #14 D:\htdocs\artisan_error\app\controllers\HomeController.php(160): Illuminate\Support\Facades\Artisan::call('migrate') #15 D:\htdocs\artisan_error\app\controllers\HomeController.php(145): HomeController->InstallDatabaseStructure() #16 D:\htdocs\artisan_error\app\controllers\HomeController.php(127): HomeController->WriteDatabaseCredentials('localhost', 'laravel-aplikac...', 'root', '') #17 [internal function]: HomeController->postTestDatabaseConnection() #18 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(231): call_user_func_array(Array, Array) #19 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('postTestDatabas...', Array)

20 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(62):

Illuminate\Routing\ControllerDispatcher->call(Object(HomeController), Object(Illuminate\Routing\Route), 'postTestDatabas...') #21 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Router.php(930): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'HomeController', 'postTestDatabas...') #22 [internal function]: Illuminate\Routing\Router->Illuminate\Routing{closure}() #23 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Route.php(105): call_user_func_array(Object(Closure), Array) #24 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Router.php(996): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request)) #25 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Routing\Router.php(964): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

26 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(738):

Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

27 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(708):

Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))

28 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Session\Middleware.php(72):

Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true) #29 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Cookie\Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true) #30 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Cookie\Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true) #31 D:\htdocs\artisan_error\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true) #32 D:\htdocs\artisan_error\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(606): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request)) #33 D:\htdocs\artisan_error\public\index.php(49): Illuminate\Foundation\Application->run() #34 {main}

Is everything done properly on my side?

composer.js contains:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.2.*",
        "way/generators": "dev-master"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}
1

4 Answers 4

23

Yes, there is a problem actually with the last version,all previous sources are not working, should use :

Artisan::call('migrate', array('--force' => true));

Tested and working fine.

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

2 Comments

This was the working answer for me running Laravel 4.2.
On Laravel 7 throws a fatal error saying --force option is not permitted
3

Use of undefined constant STDIN seems to be a Symfony error, see github.com/symfony/symfony/issues/10795.

A composer update should fix your problem.

3 Comments

@mpet, show us what your composer.json looks like. Put it in your original post.
@mpet, change minimal-stability to RC (or beta if that doesn't work), the change for the Symfony issue was pushed to 2.5.0-RC1 release.
but the right question is why it happens while using Laravel 4.2 using default values
2

I think you have to add a '-n'=>true to your call

since you are in production and a "are you sure question is fired"

so it will be like

Artisan::call('migrate',array('-n'=>true));

Comments

2

A bit of information on this topic, for anyone that comes across this:

This happens because the migrate command in a production environment will ask for confirmation. This is however not possible in the context of a web request, so the command fails. To stop it from asking for confirmation, use the --force flag.

The error Use of undefined constant STDIN - assumed 'STDIN is basically symfony telling you it has no standard input that it can use to query user input. This is expected behavior if you're not running the command in a terminal. This behavior still exists in the current version of symfony/console (5.0.* as of writing).

Also please note that trying to manually define STDIN as proposed in http://github.com/symfony/symfony/issues/10795 won't work in this case.

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.