What I need
I need to import the FPDF library, modified for the project.
What I did
Code is below, but I created a "Libraries" folder inside "App" and put the library there (with the name FPDF.php), I put in Aliasses the name of the class and its path, besides including in the composer.json
the folder path there in classmap
. I also added namespace App\Libraries\FPDF;
to the FPDF.php file within Libraries.
My folders and files structure
Whathappened
Well,youdonothavetobeageniustorealize:heisnotfindingtheclass.
config \ app.php
'aliases' => [
...
...
'FPDF' => 'App\Libraries\FPDF',
composer.json
"autoload": {
"classmap": [
"database",
"app/Libraries"
],
"psr-4": {
"App\": "app/"
}
},
HomeController.php
public function gerarPdf() {
if (Input::has('numeroDocumento') && Input::has('mesReferencia') && Input::has('anoReferencia')) {
$fpdf = new FPDF();
$fpdf->AddPage();
$fpdf->SetFont('Arial','B',16);
$fpdf->Cell(40,10,'Hello World!');
$fpdf->Output();
exit;
}
else {
return redirect()->back()->with('message', 'Por favor, digite todos os campos !');
}
}