0

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!

Shizzen83
  • 3,325
  • 3
  • 12
  • 32
  • May I ask what you are trying to achieve? Maybe you can put the functionality in [an artisan command](https://laravel.com/docs/5.8/artisan#writing-commands) and execute it that way. – Jerodev Jul 22 '19 at 08:33
  • My goal is a deployment on remote servers through SSH, but the servers may be listed either in config or database (only hosts, access is made by SSH keys) – Shizzen83 Jul 22 '19 at 08:39

1 Answers1

4

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!

Shizzen83
  • 3,325
  • 3
  • 12
  • 32