【发布时间】:2021-02-23 05:38:27
【问题描述】:
我正在尝试将dompdf 与 Laravel 一起使用,即使我使用“使用 PDF”,它仍然是错误的。
这是我的控制器
<?php
namespace App\Http\Controllers;
use RealRashid\SweetAlert\Facades\Alert;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Pasien;
use Illuminate\Support\Facades\Redirect;
use PDF;
class PasienController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$pasien = DB::table('pasien')->paginate(5);
return view('pasien/index', ['pasien' => $pasien]);
}
public function createPDF() {
// retreive all records from db
$data = Pasien::all();
// share data to view
view()->share('employee',$data);
$pdf = PDF::loadView('pdf_view', $data);
// download PDF file with download method
return $pdf->download('pdf_file.pdf');
}
}
这一行的PDF是红色的
$pdf = PDF::loadView('pdf_view', $data);
显示此消息的错误
未定义类型“PDF”
我已将其放入提供程序中
Barryvdh\DomPDF\ServiceProvider::class,
这在别名上
'PDF' => Barryvdh\DomPDF\Facade::class,
我已经使用 composer 安装了这个包,并且 php artisan vendor 发布了它。
【问题讨论】:
-
如果您刚刚安装了软件包,请尝试 config:cache 命令