Thursday, March 30, 2017

laravel 5.4: PHP Fatal error: Call to undefined method Illuminate\Foundation\Application::configure()

I am new to laravel. I am trying to use Snappy PDF from barryvdh. I have installed snappy pdf by following instruction from https://github.com/barryvdh/laravel-snappy. But when i run php artisan serve command following error is showed

PHP Fatal error: Call to undefined method Illuminate\Foundation\Application::configure() in F:\xampp\htdocs\Laravel\doctorApp\vendor\barryvdh\laravel-snappy\src\LumenServiceProvider.php on line 21

Here is that line from my LumenServiceProvider.php:

public function register()
{
   $this->app->configure('snappy'); // line 21

   $configPath = __DIR__ . '/../config/snappy.php';
   $this->mergeConfigFrom($configPath, 'snappy');
}

I have installed wkhtmltopdf using this:

$ composer require h4cc/wkhtmltopdf-amd64 0.12.x
$ composer require h4cc/wkhtmltoimage-amd64 0.12.x

in config/app.php i have added follwing lines in my providers and aliases:

in providers: Barryvdh\Snappy\ServiceProvider::class,

in aliases:

'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,

The path to the binaries in my config file (config/snappy.php): first one for pdf..

'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),

2nd one for image...

'binary' => base_path('vendor/h4cc/wkhtmltoimage-amd64/bin/wkhtmltoimage-amd64'),

my bootstrap/app.php:

<?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;

In my controller i added:

use Barryvdh\Snappy\Facades as PDF;

This is my controller:

public function PdfView(Request $request, $patient_id)
{
   $patients = Patient::where('id', $patient_id)->first();
   $pdf = PDF::loadView('pdfview', ['patients'=>$patients]);
   return $pdf->download('pdfview.pdf');

}

Can someone please say, why this error occurred and how to resolve this?



via Nazem Mahmud

Advertisement