abkrim's avatar
Level 13

barryvdh/laravel-ide-helper

I don't understand correct way for use barryvdh/laravel-ide-helper only on develop mode.

If use method on his help, get error on production because composer.json call artisan command not valid

help & doc

To install this package on only development systems, add the --dev flag to your composer command:

composer require --dev barryvdh/laravel-ide-helper

In Laravel, instead of adding the service provider in the config/app.php file, you can add the following code to your app/Providers/AppServiceProvider.php file, within the register() method:

public function register()
{
    if ($this->app->environment() !== 'production') {
        $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
    }
    // ...
}

But on composer.json

"post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan ide-helper:generate",
            "php artisan ide-helper:meta",
            "php artisan optimize"
        ]

If run composer update --no-dev or composer updateget error

> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan ide-helper:generate


  [Symfony\Component\Console\Exception\CommandNotFoundException]
  There are no commands defined in the "ide-helper" namespace.


Script php artisan ide-helper:generate handling the post-update-cmd event returned with an error


  [RuntimeException]
  Error Output:

Where is mistake? There're any way for use composer.json with two way, one for production and other for development?

Apreciate help

0 likes
3 replies
peterl38's avatar

Hi,

I have mine setup like this, composer.json:

   ` "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan optimize",
        "php artisan ide-helper:generate"
    ]`

and in app/Providers/AppServiceProvider.php:

public function register(){ if ($this->app->environment() == "local" || $this->app->environment() == "testing") {$loader = \Illuminate\Foundation\AliasLoader::getInstance(); $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class); $loader->alias("Debugbar", \Barryvdh\Debugbar\Facade::class); $this->app->register("Iber\Generator\ModelGeneratorProvider");}

if I add your:

"php artisan ide-helper:meta"

it falls over - just a thought...

abkrim's avatar
Level 13

Oh.. I get other solution.

Modify composer.json and run update on other ways.

"update-develop": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan ide-helper:generate",
            "php artisan ide-helper:meta",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ],
        "dev-update": [
            "@composer update --dev",
            "@update-develop"
        ]

Run on develop

composer update --dev

Run on production

composer --no-dev

Thanks for you post.

2 likes
hettiger's avatar

Here's a better approach:

"post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "if [ $COMPOSER_DEV_MODE -eq 1 ]; then php artisan ide-helper:generate; fi",
            "if [ $COMPOSER_DEV_MODE -eq 1 ]; then php artisan ide-helper:generate; fi",
            "if [ $COMPOSER_DEV_MODE -eq 1 ]; then php artisan ide-helper:meta; fi",
            "php artisan optimize"
]
4 likes

Please or to participate in this conversation.