Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 5.3 Class Not found #2

Closed
shadywattay opened this issue Nov 12, 2016 · 5 comments
Closed

Laravel 5.3 Class Not found #2

shadywattay opened this issue Nov 12, 2016 · 5 comments
Assignees

Comments

@shadywattay
Copy link

shadywattay commented Nov 12, 2016

After updating composer with required packages and registering in config/app.php, I've tried laravel-fpdf in laravel 5.3,

        composer.json
       "require": {
           .....
          "codedge/laravel-fpdf": "^1.0"
         },

         providers
        Codedge\Fpdf\FpdfServiceProvider::class, 
       
        aliases
        'Fpdf' => Codedge\Fpdf\Facades\Fpdf::class, 

simply in web.php routes like

Route::get('GeneratePdf', function (Codedge\Fpdf\Fpdf\FPDF $fpdf) {

	$fpdf->AddPage();
	$fpdf->SetFont('Courier', 'B', 18);
	$fpdf->Cell(50, 25, 'Hello World!');
	$fpdf->Output();

});

And I'm getting error

ReflectionException in Route.php line 339:
Class Codedge\Fpdf\Fpdf\FPDF does not exist

What could possibly be wrong ?

@codedge
Copy link
Owner

codedge commented Dec 28, 2016

Sorry for the late answer!
Did you try regenerating your Composer autoload classes with composer dump-autoload?

I tried with Laravel 5.3 both ways:

  • Separate Controller
  • Definition in routes/web.php as you did

Works flawlessly!

@kroky
Copy link

kroky commented Feb 22, 2017

May I suggest where the source of the problem is?
src/Fpdf/fpdf.php file defines a class named FPDF and the service provider searches for the correct class name FPDF all uppercase. However, it seems the psr-4 autoloader expects file name to match class name in case-sensitive fashion:
http://www.php-fig.org/psr/psr-4/

I have this failing with laravel 4.2 project with same error of Class not found. Renaming fpdf.php to FPDF.php fixes the problem. Not sure why it works sometimes but it seems file name must be fixed...

@codedge codedge reopened this Feb 22, 2017
@codedge
Copy link
Owner

codedge commented Feb 22, 2017

Thanks @kroky for checking. I'll try to investigate and will fix if I can reliably reproduce it. A better naming could indeed be a solution.

@huchenhai
Copy link

@kroky Thank you very much kroky, i'm also facing this problem. Your solution perfectly solved it , guess psr-4 couldn't find the correct file with difference on upper/lower case. As a class has to be start with Upper case , i just renamed filename as well, everything working perfectly.
cheers

@patombugua
Copy link

make sure you rename the file fpdf.php in src/Fpdf so that it start with a capital letter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants