I tried to keep running SpatiePdfToText. I have the following error:
Class ‘SpatiePdfToTextPdf’ not found
I read this but it doesn’t help.
use SpatiePdfToTextPdf; public function importInRequestStore($projectId, Request $request) { require base_path().'/vendor/autoload.php'; $text = (new Pdf()) ->setPdf('book.pdf') ->text(); }
What is wrong in this code? I do not find a solution with google.Thanks in advance.
Advertisement
Answer
It will not load the class since these spatie classes have no service providers.
You should modify the composer.json which under the root of your Laravel/Lumen project.
You can add a classmap path like below in the autoload node:
"autoload": { "classmap": [ "vendor/spatie" ] },
Or you can add a psr-4 key-value like below in the autoload node (this is the way recommanded):
"autoload": { "psr-4": [ "Spatie\": "vendor/spatie" ] },
And the last IMPORTANT thing is you should composer dump-autoload
then. Otherwise the spatie class never load in.