- How do I install cdsmths/laravel-ocr-space in a Laravel app?
- Install it with composer require cdsmths/laravel-ocr-space. The service provider and facade are auto-discovered, so you only need to publish the config file with php artisan vendor:publish and add your OCR_SPACE_API_KEY to .env. After that you can resolve the facade or inject it and start sending files or URLs, which typically takes under an hour for a Laravel-fluent developer.
- Which Laravel and PHP versions does laravel-ocr-space support?
- The package is aimed at modern Laravel applications, roughly Laravel 9 through 11 on PHP 8.1 and above, but you should confirm the exact constraints in its composer.json before committing. Because it is a thin wrapper maintained by a single developer, its Laravel and Guzzle version constraints may lag behind the newest framework release. Check that the Laravel HTTP client and Guzzle versions resolve cleanly against your host app.
- How do I configure my OCR.space API key in Laravel?
- Publish the package config file and set OCR_SPACE_API_KEY in your .env file, mirroring the standard Laravel configuration pattern. Keep the key out of version control and remember to run php artisan config:cache as part of deployment so the cached config picks up the value. If you use multiple environments, give each one its own key so you can track quota usage separately.
- Can I send image URLs instead of uploading files with this package?
- Yes. OCR.space accepts either an uploaded file or a publicly reachable URL, and the Laravel wrapper exposes both paths so you can pass a remote image link or a local file. Uploading from a storage disk is usually safer for private documents, since a URL-based call requires the vendor to be able to fetch the asset. Validate file type and size before sending, because the API will reject oversized or unsupported inputs.
- Does laravel-ocr-space support PDFs, and are there page limits?
- Yes, the package supports PDFs as well as images because OCR.space handles both formats. The free tier of OCR.space caps files at roughly 1 MB and limits PDFs to about 3 pages, so multi-page invoices or contracts will need a paid plan. Validate page counts and file sizes in your own pipeline before dispatching a request to avoid wasted quota.
- Can I run OCR with laravel-ocr-space inside a queued Laravel job?
- The package is essentially a typed HTTP client and does not ship its own queue layer, so you wrap the call in your own job class. Running OCR in a queued job keeps slow external requests off the request cycle and gives you retries, backoff, and timeouts through Laravel's queue configuration. Since extraction can take seconds per document, queueing is strongly recommended for any document-intake feature.
- How should I handle OCR.space timeouts, quota errors, and malformed responses?
- Because every call crosses the network to an external SaaS, treat timeouts, rate-limit responses, and unexpected payloads as normal failure modes rather than exceptions. The wrapper typically returns the decoded vendor response rather than domain objects, so normalize the shape into your own DTO at the boundary and validate that the text field exists and is non-empty. Configure explicit HTTP timeouts, retry middleware with backoff, and proxy settings, since corporate proxies are a common silent failure point.
- Is it safe to send sensitive documents to OCR.space from a Laravel app?
- Images and PDFs leave your infrastructure and are processed by a third-party, US-hosted API, which is a blocker for regulated data such as PHI, PII, or financial records unless you have an approved data processing agreement and a residency story. Raise this with legal and security before building the feature, not after. Keeping the call behind your own provider interface also lets you swap to an on-premise engine such as Tesseract if compliance rules tighten.
- How do I test code that uses laravel-ocr-space without calling the real API?
- Mock the facade or the underlying Laravel HTTP client so tests never hit ocr.space and never consume quota. Faking responses also lets you assert behavior for success, quota-exceeded, and malformed payload cases, which are the ones most likely to break in production. Keep a few recorded real responses as fixtures so your parser is tested against the actual vendor shape.
- What are the alternatives to laravel-ocr-space, and is the package actively maintained?
- Alternatives include cloud OCR services such as AWS Textract or Google Cloud Vision, self-hosted engines like Tesseract or OCRmyPDF, or a direct Guzzle implementation against the OCR.space REST API. The package is MIT licensed with roughly 125 stars and a single maintainer, so treat it as a convenience layer rather than a strategic dependency. Wrapping it behind your own OcrProvider contract, and confirming you could fork it if needed, keeps your application insulated from package or vendor churn.