从自定义php脚本访问Laravels类



我写了一个脚本,每天午夜由crontab运行。该脚本基本上将检查模型中的一些数据。所以这个脚本是非常独立于整个应用程序。我需要访问laravel类,如碳,模型,数据库等。我如何导入它们以在脚本中使用?

我基本上检查了index.php文件中的代码,因为整个应用程序都在那里运行,看到了自动加载器,然后在我想要运行的自定义脚本中需要它,它工作了。我可以访问应用程序中的所有类。我把代码放在下面。

namespace App;
use IlluminateContractsHttpKernel;
use IlluminateHttpRequest;
define('LARAVEL_START', microtime(true));
require_once("vendorautoload.php");
$app = require_once("bootstrapapp.php");
$kernel = $app->make(Kernel::class);
$response = $kernel->handle(
$request = Request::capture()
);

最新更新