angrydeer / attachfiles
Add some attached files to Eloquent model and store it to storage/app/attached/{Y-m-d} dir.
Installs: 1 725
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.4.0
- illuminate/support: ~5.1
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2025-02-15 20:17:37 UTC
README
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.