Error on Artisan commands when updating Composer dependencies
<p>I am developing a library for Laravel which contains a service provider. I have added this library to another project's <code>composer.json</code> file.</p>

<p>The <code>composer.json</code> file for the "main project" contains the following scripts.</p>

<pre><code>"scripts": {
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ]
},
</code></pre>

<p>I can include the library dependency just fine, except for one thing; the <code>pre-update-cmd</code> and <code>post-update-cmd</code> scripts throw an error and cause me a lot of headaches. When running <code>sudo composer update</code> to update the dependencies, I get the following error.</p>

<pre><code>$ sudo composer update
&gt; php artisan clear-compiled
PHP Fatal error:  Class 'MyName\MyProject\MyAwesomeServiceProvider' not found in /Users/Me/dev/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146


  [Symfony\Component\Debug\Exception\FatalErrorException]                                              
  Class 'MyName\MyProject\MyAwesomeServiceProvider' not found  


Script php artisan clear-compiled handling the pre-update-cmd event returned with an error


  [RuntimeException]                                                                                         
  Error Output: PHP Fatal error:  Class 'MyName\MyProject\MyAwesomeServiceProvider' 
  not found in /Users/Me/dev/MyProject/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
</code></pre>

<p>I have Googled around quite a bit before asking this question and read through pretty much everything related that I could find. Apparently this is a known issue that has been discussed in multiple GitHub issues within the Laravel repository. However, I have yet to find a workaround, even after having tried multiple ones.</p>

<p>It appears that the issue is that the Artisan commands bootstrap Laravel, which leads to an error because the service provider is not available at this point - or something like that. Moving the <code>clear-compiled</code> command to <code>post-update-cmd</code> causes the same error, which surprises me a bit because I thought the service provider would be available at this point.</p>

<p>The only thing that works for me is to manually comment out the line that includes the service provider in <code>config/app.php</code> before running <code>composer update</code> and then adding it again afterwards. I have been doing this for a few hours, and it is already bothering the heck out of me, and I really cannot believe that this issue is around.</p>

<p>Does anyone know how to work around this error so that I don't get the error that my service provider is not found when updating the Composer dependencies for my project?</p>

<p><strong>EDIT:</strong>
Here is the <code>composer.json</code> file for the library.</p>

<pre><code>{
    "name": "my-name/my-project",
    "type": "library",
    "authors": [
        {
            "name": "My Name",
            "email": "test@example.com"
        }
    ],
    "require": {
        "php": "&gt;=5.5.0",
        "laravel/framework": "~5.2"
    },
    "autoload": {
        "classmap": [],
        "psr-4": {
            "MyName\\MyProject\\": "src/"
        }
    }
}
</code></pre>