我是laravel的新手。我正在尝试使用barryvdh的Snappy PDF。我按照https://github.com/barryvdh/laravel-snappy的指示安装了snappy pdf。但是当我运行[Enter]
命令后,显示错误
PHP致命错误:在第21行的F:\ xampp \ htdocs \ Laravel \ doctorApp \ vendor \ barryvdh \ laravel-snappy \ src \ LumenServiceProvider.php中调用未定义的方法Illuminate \ Foundation \ Application :: configure()< / p>
这是我的LumenServiceProvider.php中的那一行:
php artisan serve
我用这个安装了wkhtmltopdf:
public function register()
{
$this->app->configure('snappy'); // line 21
$configPath = __DIR__ . '/../config/snappy.php';
$this->mergeConfigFrom($configPath, 'snappy');
}
在config / app.php中,我在我的提供者和别名中添加了以下行:
提供商中的:$ composer require h4cc/wkhtmltopdf-amd64 0.12.x
$ composer require h4cc/wkhtmltoimage-amd64 0.12.x
:
Barryvdh\Snappy\ServiceProvider::class,
我的配置文件中的二进制文件的路径(config / snappy.php):第一个用于pdf ..
'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,
第二张图片......
'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
我的bootstrap / app.php:
'binary' => base_path('vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64'),
在我的控制器中我添加了:
<?php
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
/*snappy pdf start--- i added this part*/
class_alias('Barryvdh\Snappy\Facades\SnappyPdf', 'PDF');
$app->register(Barryvdh\Snappy\LumenServiceProvider::class);
//Optionally, add the facades like so:
class_alias(Barryvdh\Snappy\Facades\SnappyPdf::class, 'PDF');
class_alias(Barryvdh\Snappy\Facades\SnappyImage::class, 'SnappyImage');
/*snappy pdf end*/
$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
);
return $app;
这是我的控制者:
use Barryvdh\Snappy\Facades as PDF;
有人可以说,为什么会出现此错误以及如何解决此问题?
答案 0 :(得分:3)
如果您使用的是Laravel,则不应使用LumenServiceProvider,而是:
Barryvdh\Snappy\ServiceProvider::class,
如包文件中所述
修改强>
好的,我看到问题不同,再次阅读。你补充说:
class_alias('Barryvdh\Snappy\Facades\SnappyPdf', 'PDF');
$app->register(Barryvdh\Snappy\LumenServiceProvider::class);
//Optionally, add the facades like so:
class_alias(Barryvdh\Snappy\Facades\SnappyPdf::class, 'PDF');
class_alias(Barryvdh\Snappy\Facades\SnappyImage::class, 'SnappyImage');
进入bootstrap/app.php
,但你不应该。这仅适用于Lumen,不适用于Laravel