Search code examples
phplaravellaravel-5composer-phplaravel-envoy

Laravel Envoy - Class config does not exist


I'm currently trying to use Laravel Envoy ( https://laravel.com/docs/5.8/envoy ). It works fine but I would like going further by being able to use Illuminate\Foundation\Application class to be able to inject some dependencies into @setup Envoy directive (e.g. retrieve some config or Eloquent models). But I keep getting this error, whatever I tried.

enter image description here

My Envoy.blade.php file:

@servers(['localhost' => '127.0.0.1'])

@include('vendor/autoload.php')

@setup
    $laravelApp = include 'bootstrap/app.php';
    dump(config('database'));
@endsetup

@task('foo', ['on' => 'localhost'])
    ls
@endtask

Any help would be greatly appreciated, thanks!


Solution

  • I finally found out the origin of my issue. It came from Laravel bootstrappers which are not called. They get called by a Kernel class instead of Application. So, I added this to make it work:

    @servers(['localhost' => '127.0.0.1'])
    
    @setup
        define('LARAVEL_START', microtime(true));
    
        $app = require_once __DIR__.'/bootstrap/app.php';
    
        $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
    
        $kernel->bootstrap();
    
        dump(config('database'));
    @endsetup
    
    @task('foo', ['on' => 'localhost'])
        ls
    @endtask
    
    

    Notice that bootstrappers are not automatically called, and because I do not wish using Artisan on this use-case, I called bootstrap method manually.

    Thanks anyway for your help!