Download the PHP package cbcaio/image-attacher without Composer
On this page you can find all versions of the php package cbcaio/image-attacher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package image-attacher
Image Attacher
This package uses polymorphic relationships to easily attach images to models. Basically you just need to use one of the package's traits in your model and you are good to go(see Usage). What happens in the background is that the models are linked to the images by a MorphOne relationship and every time you persist a image into the associated table the file is written automatically using the selected driver (using Flysystem), or updated if needed.
Install
1 - Via Composer
To get started with Image Attacher, add it to your composer.json
file as a dependency:
2 - Provider
After installing the Image Attacher, register the CbCaio\ImgAttacher\Providers\ImgAttacherServiceProvider
in your configuration file (config/app.php
):
'providers' => [
// Other service providers...
CbCaio\ImgAttacher\Providers\ImgAttacherServiceProvider::class,
],
3 - Configuration
In order to publish the configuration files run the following command
This command will create 3 new files:
-
config/img-attacher.php
: this file holds the Image Attacher configurations.-
path_to_save
: defines where images will be saved, relatively to the driver and local specified in theflysystem.php
. This path will be parsed before being used. The :attribute
references information about theattacherImage
model while the :owner_class
and :owner_id
are relative to the owner class of the relationship. These are needed to organize folders and also to certify that the right image will be deleted.IMPORTANT: This path should be exclusively used by the package, do not put other files in the same folder otherwise they can be deleted by mistake.
processing_styles
andprocessing_style_routines
: the 'routine' represents a sequence of 'styles' and its needed methods. Each 'style' saves a copy of the original image with the modifications specified in its method. They can be used to save different versions of your original image automatically when you add an image to a model (the model can can have different 'versions'/'styles' of same image with only one relationship).- For example, the following code will save the original image and also a 'thumbnail
version' of the same image in their respective parsed
path_to_save
with :style
substituted byoriginal_style
andthumbnail
:
- For example, the following code will save the original image and also a 'thumbnail
version' of the same image in their respective parsed
-
-
database/migrations/2016_01_12_000000_create_attacher_images_table
: this is a migration file to create the table which will hold the reference to your models in the MorthOne relationship and the information about the images. config/flysystem.php
: this file is relative to the Flysystem. How and where your files will be written is defined here. It is important to say that this package is only tested using the 'local' driver.
Usage
To start attaching images to your models you just need to use one of the available traits (currently only hasImage
) in
the model.
class RandomModel extends Model
{
use hasImage;
}
1 - Basic of using the hasImage trait
Adding an image to the model from an uploaded file.
Retrieving an image from the model.
Adding another image
Deleting image and all the its styles
Change log
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONDUCT for details.
Security
If you discover any security related issues, please email :author_email instead of using the issue tracker.
Credits
- CbCaio
- vinicius73
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of image-attacher with dependencies
illuminate/database Version ~5
graham-campbell/flysystem Version ~3.3
intervention/image Version ~2.3