Documents Manager

Codacy BadgeStyleCILicenseTotal DownloadsLatest Stable Version

Documents Manager for Laravel Enso.

Watch the demo

click on the photo to view a short demo in compatible browsers

Features

  • permits the management (upload, download, delete, show) of documents in the application
  • can attach documents to any other model
  • comes with its own VueJS components
  • uses FileManager for file operations
  • uses the ImageTransformer package for optimizing the uploaded image files
  • security policies are used to enforce proper user authorization
  • comes with a Documentable trait that can be quickly added to the model you want to give this functionality to
  • offers various configuration options, including the option to delete all attached documents to a Documentable entity, when it gets deleted

Under the Hood

  • creates a Document model that has a documentable morphTo relationship
  • polymorphic relationships are used, which makes it possible to attach documents to any other entity
  • within the entity to which we want to attach documents, we must use the Documentable trait
  • once documents are attached to an entity, you should not be able to delete the entity without deciding what you want to do with the associated documents. This is configurable in the options, see below

Installation Steps

This package is already included in Laravel Enso, so no further steps are necessary.

Usage

  1. Import the VueJS component in your page/component and then compile
import Documents from '../../../components/enso/documents/Documents.vue';
  1. Add the component inside your page/component
<documents 
    id="modelId"
    type="model_class">
</documents>

Note: you may substitute the documents component with the documents-card component as the two share the main properties and the documents-card is a card wrapper for the bare documents component.

  1. Add use Documentable in the Model that need documents and import the trait. Then you'll have access to the $model->documents relationship

  2. Because users upload documents you can add use Documents to the User model. This trait will set the relationship between users and the documents that they create

IMPORTANT NOTE:

Since this package is using image processing libraries and these underlying libraries may use a lot of memory, especially if the processed files are large (for example, for an 8MB image file, more than 128MB of memory might be used ), make sure to configure php accordingly and/or do ini_set(‘memory_limit’, ‘256M’);

Failure to do so may result in silent errors if allotted memory is insufficient.

Options

DocumentsCard.vue

  • id - number, the id of the documentable model | required
  • type - string, the documentable model class | required
  • open - boolean flag, makes the component start collapsed or open | default is false | (optional)
  • title - string, title for the component | default '' | (optional)

Documents.vue

  • id - number, the id of the documentable model | required
  • type - string, the documentable model class | required
  • query - string, text used for filtering the documents| default null | (optional)
  • controls - boolean, used for showing the controls buttons | default false | (optional)

Configuration

The config/enso/documents.php configuration file, lets you customize the following:

  • deletableTimeLimit - the time limit for deleting an uploaded document, in seconds. Default is 60 * 60 (1 hour)

  • linkExpiration, - the time limit for document share link, in seconds. Default is 60 * 60 * 24 (1 day)

  • imageWidth - the image width, in pixels, used when resizing bigger picture files. Default is 2048

  • imageHeight - the image height, in pixels, used when resizing bigger picture files. Default is 2048

  • onDelete, string, option that manages the case when the commentable entity is deleted and it has attached addresses. Valid options are cascade, restrict | default is cascade

    With the cascade option, when a commentable model is deleted, the comments attached to it are also deleted. With the restrict option, when attempting to delete a commentable model with attached comments, an exception is thrown.

  • loggableMorph, the list of entities using the commentable functionality, each mapped to its respective loggable attribute For example:

    'commentable' => [
        Company::class => 'name',
    ],
    

    This configuration is used for activity logging.

Publishes

  • php artisan vendor:publish --tag=documents-assets - the VueJS components
  • php artisan vendor:publish --tag=documents-config - configuration file
  • php artisan vendor:publish --tag=enso-assets - a common alias for when wanting to update the VueJS components, once a newer version is released, usually used with the --force flag
  • php artisan vendor:publish --tag=enso-config - a common alias for when wanting to update the config, once a newer version is released, usually used with the --force flag

Notes

The Laravel Enso package comes with this package included.

Depends on:

Last Updated: 11/12/2018, 4:35:32 PM