Giter Club home page Giter Club logo

laravel-attachments-1's Introduction

Attach files to Eloquent models

This package gives you models, traits and some examples for attaching files to any Eloquent model and write down those usages. Also provides use of private files (downloaded through framework with user token).

Possible flow:

  1. You upload a file
  2. Create Attachment model for this file
  3. Write down usage of this attachment by your model

If you delete this model, usage will be deleted. If you reSave your model with another attachment - usage will be deleted.

Unused attachments can be deleted by running cleanup (@see Facades/Attachments).

Uploaded images can be automatically resized to max size given in config, there is a job for that.

See AttachmentManager for further usage.

Made for Rest API projects. Ideally must be controller for file upload and another one for download (private files). Controller examples are in src/Controllers directory.

There is also image processing controller example, which uses hexadecimal encoded width/height data, it is resizing images on the fly and puts resized images to the cache folder. You can use NGINX, for example, to download cached image next time.

Traits

You can found usable model traits in src/Traits directory. They use an observer for save/delete events.

  • HasAttachments - General trait for use withing model
  • HasAttachmentById - trait for model with single attachment_id field

Console

Create migration

You can create DB migration for Attachment models by running artisan command:

php artisan attachments:tables

Create directories fo files

Command will create directories for attachments save/publishing.

php artisan attachments:directories

laravel-attachments-1's People

Contributors

devmoroh avatar digitv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.