Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/guimcaballero/laravel-folders
File folders in Laravel!
https://github.com/guimcaballero/laravel-folders
Last synced: 22 days ago
JSON representation
File folders in Laravel!
- Host: GitHub
- URL: https://github.com/guimcaballero/laravel-folders
- Owner: guimcaballero
- License: mit
- Created: 2020-04-22T16:07:53.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-05T10:15:49.000Z (over 4 years ago)
- Last Synced: 2024-04-25T17:43:07.348Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Description
[![Latest Version on Packagist](https://img.shields.io/packagist/v/guimcaballero/laravel-folders.svg?style=flat-square)](https://packagist.org/packages/guimcaballero/laravel-folders)
[![Build Status](https://img.shields.io/travis/guimcaballero/laravel-folders/master.svg?style=flat-square)](https://travis-ci.org/guimcaballero/laravel-folders)
[![Quality Score](https://img.shields.io/scrutinizer/g/guimcaballero/laravel-folders.svg?style=flat-square)](https://scrutinizer-ci.com/g/guimcaballero/laravel-folders)
[![Total Downloads](https://img.shields.io/packagist/dt/guimcaballero/laravel-folders.svg?style=flat-square)](https://packagist.org/packages/guimcaballero/laravel-folders)This is a very simple package that implements Folders, where you can save as many files as you want to a model, while only having one column.
Folders behave just like a normal folder on you OS would, you can add, remove and list files. Adding files doesn't remove existing files.
## Installation
You can install the package via composer:
```bash
composer require guimcaballero/laravel-folders
```Then run the migrations:
```bash
php artisan migrate
```# Configuration
You can publish the migrations with:
```bash
php artisan vendor:publish --provider="Guimcaballero\LaravelFolders\LaravelFoldersServiceProvider"
```## Example
This is a simple use case where we want to be able to upload a list of important files in a User:
In App\User:
```php
morphOne(Folder::class, 'folderable');
}
}
```Then in web.php:
```php
Route::post('user/uploadImportantFiles', function(Request $request) {
$folder = auth()->user()->importantDocuments;
$folder->uploadFiles($request->file('files'));dd($folder->getListOfFiles());
});
```# Usage
## Add a folder to a model
To add a folder to a model, add the following to the model class:
```php
public function importantFiles()
{
return $this->morphOne(Folder::class, 'folderable');
}
```## Create a folder
To create a folder run:
```php
$folder = Folder::createNewRandomFolder();
$user->importantFiles()->save($folder);
```## List all files in a folder
```php
$folder->getListOfFiles();
```This will return an array with the files inside the folder.
## Uploading multiple files
You can upload multiple files at once with:
```php
$folder->uploadFiles($request->file('files'));
```## Uploading a single file
You can upload a single file with:
```php
$folder->uploadSingleFile($request->file('file'));
```## Removing files
To remove multiple files, pass an array containing the names of the files:
```php
$folder->removeFiles(['importantFile1.pdf', 'importantFile2.pdf']);
```## Removing a single file
To remove a single file, pass the name of the file:
```php
$folder->removeSingleFile('importantFile1.pdf');
```## Multiple folders
You can have more than one folder in a class, like for example:
```php
public function importantDocuments()
{
return $this->morphOne(Folder::class, 'folderable')->where('folderable_group', 'important');
}public function lessImportantDocuments()
{
return $this->morphOne(Folder::class, 'folderable')->where('folderable_group', 'less_important');
}
```You then have to pass the corresponding group when creating the folder:
```php
$folder = Folder::createNewRandomFolder('important');
$user->importantFiles()->save($folder);
```### Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Feel free to Contribute to this project!
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits
- [Guim Caballero](https://github.com/guimcaballero)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.