Package to add Images to models
Usage
- Install via composer
- If Laravel 5.4 or lower, add service provider
Beestreams\LaravelImageable\ImageableProvider::class
- run
php artisan vendor:publish --tag=config
- Migrate database
- Include Imageable trait on models
- Set upload path on model
protected $imagePath = 'example/'
- When file is available, add it to model
$model->attachImage($file);
When file is added to model, it first persists an Image model to DB
it then saves the file to specified path.
You can set sizes in config to make several images. These are jobs dispatched to queue.
For each image size it makes an additional model.
When model is deleted, it also deletes the file.
When original model is deleted all related models and files are deleted, (*1)
For method list see Imageable trait or IntegrationTest, (*2)
If you want alt_text and description for your files … support for that is coming, (*3)
TODO:
- Get file from url (route and response)
- Multiple file types support
- SVG support
- create failsafe in ResizeImage job. If size does not exist, fail gracefully
- Integrationtest is a test-dump. Clean up and refactor
- Fix hacky Job handle method
- Whats up with all the save methods?
- External storage services
- Delete all sizes on delete
- Create controller for image and refactor routes file
- If file directory is empty remove directory on delete, (*4)
Important
There is no validation in this package, please validate your requests before using., (*5)
Vendor publish
If you need to modify migrations, models or traits you can ´vendor:publish´ this package. (not tested), (*6)