PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 24, 2022

[FIXED] Autoloading 3rd party composer packages into Laravel 5 Application

 January 24, 2022     composer-php, laravel, laravel-5, php     No comments   

Issue

I am trying to get my head around Composer. I want to integrate this package into my app: https://github.com/thiagoalessio/tesseract-ocr-for-php

I have done the following so far:

composer require thiagoalessio/tesseract_ocr 
composer dump-autoload

and I have used the library within a Controller method as such:

$tesseract = new TesseractOCR($url);

But I'm getting the dreaded:

Class 'App\Http\Controllers\TesseractOCR' not found

How do I make sure that composer autoloads the package and that it is available throughout the apps, for usage within controllers?

Sorry, newbie in Composer here..


Solution

Composer has auto-loaded the package, you’re just referencing the class name incorrectly.

TesseractOCR lives in the “global” namespace, so you need to import it:

use TesseractOCR;

You can then use it in your controllers etc as normal.



Answered By - Martin Bean
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing