hlacos/attachment

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel attachment bundle

dev-master 2015-02-14 12:09 UTC

This package is auto-updated.

Last update: 2020-02-13 12:22:14 UTC


README

Eloquent extension for store simply file attachments.

It's under development, not recommended for production use!

Installation

  1. add bundle to composer: "hlacos/attachment": "dev-master"
  2. composer install
  3. add service provider to the providers list: 'Hlacos\Attachment\AttachmentServiceProvider'
  4. php artisan migrate --package="hlacos/attachment"
  5. create directory: public/attachments
  6. let it write by the web server

Attachments storing in public/attachments directory. To override it:

  1. php artisan config:publish hlacos/attachment
  2. edit app/config/packages/hlacos/attachment.php

Usage

$attachment = new Attachment;
$attachment->addFile($filename);
$attachment->attachable()->associate($relatedModel);
$attachment->save();

Override table

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;

Related models

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');
}