Laravel 5 bundle for store simply file attachments.
It's under development, not recommended for production use!
- add bundle to composer: "hlacos/attachment5": "dev-master"
- composer install / update
- add service provider to the providers list: 'Hlacos\Attachment5\Attachment5ServiceProvider'
- publish config and migration: php artisan vendor:publish --provider="Hlacos\Attachment5\Attachment5ServiceProvider"
- php artisan migrate
- create directory: public/attachments
- let it write by the web server
Attachments storing in public/attachments directory. To override it:
- edit config/attachment5.php
$attachment = new Attachment; $attachment->addFile($filename); $attachment->attachable()->associate($relatedModel); $attachment->save();
Extend Hlacos\Attachment5\Models\Attachment and set the $table attribute.
Extend Hlacos\Attachment5\Models\Attachment and set the $sizes array attribute. In the array sets the width of the required images;
Extend Hlacos\Attachment5\Models\Attachment and set the $originalMaxSize string attribute.
You can set polymoprhic relations in the realted models.
public function attachment() {
return $this->morphOne('Hlacos\Attachment5\Models\Attachment', 'attachable');
}
public function attachment() {
return $this->morphMany('Hlacos\Attachment5\Models\Attachment', 'attachable');
}
Thanks to David Beyaty (https://github.com/hatja) for the gif resize implementation.