从外部启动整个Laravel5应用程序

I'm trying to boot entire L5 application from an external php script. I need to get access to Eloquent models and facades. For example, I have two installed and working applications in separate folders:

  • /var/www/drupal7
  • /var/www/drupal7/laravel

my nginx vhost config:

location /laravel {
      root   /var/www/drupal7/laravel/public;
      index index.php;
      try_files $uri $uri/ /laravel/public/index.php?$query_string;
}

my /var/www/drupal7/laravel/routes/web.php

Route::get('/laravel', function () {
    return 'Laravel';
});

Both applications works fine, but I need to boot laravel app from external script and I want to get access to models, views, configs. My question is - how can I do this properly?

I tried to achieve this using below code:

<?php

require '/var/www/drupal7/laravel/bootstrap/autoload.php';

$app = new Illuminate\Foundation\Application(
    '/var/www/drupal7/laravel/'
);

$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    App\Http\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    App\Exceptions\Handler::class
);

use App\User;

$user = User::find(1);
var_dump($user);

but I get follow error message:

Error: Call to a member function connection() on null in Illuminate\Database\Eloquent\Model::resolveConnection() (line 1013 of /var/www/drupal7/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php)

Try this

<?php
// boot laravel
require __DIR__ .'/../../vendor/autoload.php';
$laravel_app = require __DIR__ .'/../../bootstrap/start.php';
$laravel_app->boot();

See this article for the solution that helped me