【发布时间】:2017-08-24 16:50:49
【问题描述】:
我想使用命令从终端执行 DomPDF 下载。 CLI 命令使用 Guzzle 执行 API 调用。我做了一个非常简单的设置。
问题
500 服务器错误
[GuzzleHttp\Exception\ServerException]
Server error: `GET http://localhost:8888/pdf` resulted in a `500 Internal S
erver Error` response:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow (truncated...)
API 调用
命令
php 工匠 pdf
项目结构
- 命令
- PDFCommand.php
- 控制器
- PDFController.php
- 查看次数
- rapport.blade.php
源代码
路线
Route::get('pdf', 'PDFController@downloadPDF');
PDFCommand.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use GuzzleHttp\Client as GuzzleClient;
class PDFCommand extends Command
{
protected $signature = 'pdf';
protected $description = 'download pdf';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$client = new GuzzleClient;
$client->request('GET', 'http://localhost:8888/pdf');
}
}
PDFController.php
<?php
namespace App\Core;
use App\Http\Controllers\Controller;
use Barryvdh\DomPDF\Facade as PDF;
class PDFController extends Controller
{
private $pdf;
private $client;
public function downloadPDF()
{
$this->pdf = PDF::loadView('report');
return $this->pdf->download('report.pdf');
}
}
rapport.blade.php
<!doctype html>
<html>
<head>
<title>Rapport</title>
</head>
<body>
<h1>TEST</h1>
<p>Dit is een test</p>
</body>
</html>
【问题讨论】: