Eloquent extension for store simply file attachments.
It's under development, not recommended for production use!
- add bundle to composer: "hlacos/attachment": "dev-master"
- composer install
- add service provider to the providers list: 'Hlacos\Attachment\AttachmentServiceProvider'
- php artisan migrate --package="hlacos/attachment"
- create directory: public/attachments
- let it write by the web server
Attachments storing in public/attachments directory.
To override it:
- php artisan config:publish hlacos/attachment
- edit app/config/packages/hlacos/attachment.php
$attachment = new Attachment;
$attachment->addFile($filename);
$attachment->attachable()->associate($relatedModel);
$attachment->save();
Extend Hlacos\Attachment\Attachment and set the $table attribute.
Set uploadable image required sizes
Extend Hlacos\Attachment\Attachment and set the $sizes array attribute.
In the array sets the width of the required images;
You can set polymoprhic relations in the realted models.
public function attachment() {
return $this->morphOne('Hlacos\Attachment\Attachment', 'attachable');
}
public function attachment() {
return $this->morphMany('Hlacos\Attachment\Attachment', 'attachable');
}