angrydeer/attachfiles

Add some attached files to Eloquent model and store it to storage/app/attached/{Y-m-d} dir.
1,725 1
Install
composer require angrydeer/attachfiles
PHP:>=5.4.0
License:MIT
Last Updated:Feb 18, 2016
Links: GitHub  ·  Packagist
Maintainer: Angrydeer

Laravel 5.2 Attachfiles

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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.

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.

When you remove attach, file is deleted from Storage.

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.

Install

Add to composer.json in require section:

"angrydeer/attachfiles": "dev-master"

Make composer update

after that add to config/app.php:


'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
         Angrydeer\Attachfiles\AttachfilesServiceProvider::class,
         // ...
     ],

console:

$ php artisan vendor:publish
$ php artisan migrate

Usage

In model:


// 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:


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

in view:


        @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.

Contributing

Please see CONTRIBUTING and CONDUCT for details.

issues

If you discover any related issues, please using the issue tracker.

Credits

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

License

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

Related Packages

angrydeer/productso

Manage products and categories in Laravel 5 with Sleeping-owl admin panel

23 1
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

641,106,524 9,700
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

502,645,077 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

418,291,778 609