Documents adds polymorphic document attachments to Enso models.
The package stores uploaded documents through the Enso files layer, exposes document listing, upload, and delete endpoints, supports configurable deletion rules for related models, and can queue OCR for PDF documents whose owners implement the Ocrable contract.
It is meant for backoffice models that need a lightweight document vault with optional OCR processing.
Install the package:
composer require laravel-enso/documentsRun the package migrations:
php artisan migrateOptional publish:
php artisan vendor:publish --tag=documents-configDefault configuration:
return [
'deletableTimeLimit' => 60 * 60,
'imageWidth' => 2048,
'imageHeight' => 2048,
'onDelete' => 'restrict',
'loggableMorph' => [
'documentable' => [],
],
'queues' => [
'ocr' => 'heavy',
],
];- Polymorphic one-to-one and one-to-many document relations via the
Documentabletrait. - File attachment handling through
laravel-enso/files. - Upload, list, and delete API under
core.documents. - Configurable delete policy with
restrictorcascade. - OCR dispatch for PDF documents whose owner implements
Ocrable.
Add the trait to any model that should own documents:
use Illuminate\Database\Eloquent\Model;
use LaravelEnso\Documents\Traits\Documentable;
class Order extends Model
{
use Documentable;
}Available relations:
document()documents()
If the owning model should trigger OCR for uploaded PDFs, implement LaravelEnso\Documents\Contracts\Ocrable.
GET api/core/documentsPOST api/core/documentsDELETE api/core/documents/{document}
Route names:
core.documents.indexcore.documents.storecore.documents.destroy
LaravelEnso\\Documents\\Models\\Document
Useful methods:
store(array $request, array $files)scopeFor(array $params): BuilderscopeFilter(?string $search): Builder
Required Enso packages:
laravel-enso/core↗laravel-enso/files↗laravel-enso/helpers↗laravel-enso/image-transformer↗laravel-enso/migrator↗laravel-enso/ocr↗laravel-enso/track-who↗laravel-enso/users↗
Companion frontend package:
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!