2017 © Pedro Peláez
 

library attachfiles

Add some attached files to Eloquent model and store it to storage/app/attached/{Y-m-d} dir.

image

angrydeer/attachfiles

Add some attached files to Eloquent model and store it to storage/app/attached/{Y-m-d} dir.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

Laravel 5.2 Attachfiles

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Intro

Developed for easy work with the administration panel, such as Sleeping-Owl admin where all downloaded files are stored in a single folder and are not deleted if the record is not saved., (*2)

Attahfiles creates a link between a record of any model and a collection of downloaded files. He keeps them in the Storage assigning unique names, creates a new folder for each month, and day and deletes the originals from the shared folder upload., (*3)

When you remove attach, file is deleted from Storage., (*4)

You can add a file field Title, Alt, and Description. If the field Alt while maintaining empty, it is taken as the original file name., (*5)

Install

Add to composer.json in require section:, (*6)

``` php "angrydeer/attachfiles": "dev-master", (*7)


Make composer update after that add to config/app.php: ``` php 'providers' => [ /* * Laravel Framework Service Providers... */ Angrydeer\Attachfiles\AttachfilesServiceProvider::class, // ... ],

console:, (*8)

``` bash $ php artisan vendor:publish $ php artisan migrate, (*9)





## Usage In model: ``` php // beginning omitted use Angrydeer\Attachfiles\AttachableTrait; use Angrydeer\Attachfiles\AttachableInterface; class SomeModel extends Model implements AttachableInterface { use AttachableTrait; public function myfunc() { $model = SomeModel::find(1); $model->updateOrNewAttach($filename, $title, $alt, $desc); $model->removeAttach($filename); $all_attach_files = $model->attaches; $filearray = [ 'file1', 'file12', 'file3' ] /* * as example, in $all_attach_files now attaches with 'file2', 'file3', 'file4' * */ $model->keepOnly($filearray); $all_attach_files = $model->attaches; // 'file2', 'file3' included. file4 removed. } }

in route.php you can write for images as example:, (*10)

``` php, (*11)

Route::get('attaches/{date}/{filename}', function ($date,$filename) {
    return Storage::get('attaches/'.$date.'/'.$filename);
});

in view: ``` php @foreach($model->attaches as $attach) <img src="{{URL::to($attach->filename)}}" alt="{{$attach->alt}}" title="{{$attach->title}}"> @endforeach

Change log

Please see CHANGELOG for more information what has changed recently., (*12)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*13)

issues

If you discover any related issues, please using the issue tracker., (*14)

Credits

  • [AngryDeer][http://angrydeer.ru]

License

The MIT License (MIT). Please see License File for more information., (*15)

The Versions

18/02 2016

dev-master

9999999-dev https://github.com/AngryDeer/Attachfiles

Add some attached files to Eloquent model and store it to storage/app/attached/{Y-m-d} dir.

  Sources   Download

MIT

The Requires

 

The Development Requires

angrydeer attachfiles