Skip to content

Commit

Permalink
readme fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MonstreX committed Jan 11, 2021
1 parent 14df41d commit ebf5753
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":4445:{a:2:{s:7:"defects";a:25:{s:59:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testBasicTest";i:3;s:80:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testGetShouldReturnEmptyCollection";i:4;s:68:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::it_runs_the_migrations";i:3;s:85:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_get_should_return_empty_collection";i:4;s:62:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testDBRecordTest";i:3;s:69:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_record_check";i:4;s:69:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_record_exist";i:4;s:64:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_avatar_upload";i:3;s:60:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_add";i:4;s:90:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_get_should_return_empty_collection";i:4;s:65:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add";i:3;s:74:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_record_exist";i:3;s:74:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_record_check";i:3;s:66:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add2";i:4;s:62:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddFile";i:3;s:77:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddOneFileAsUploadFile";i:4;s:86:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddGetDeleteOneFileAsUploadFile";i:4;s:77:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddDeleteOneFileAsPath";i:4;s:76:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddGetDeleteManyFiles";i:4;s:60:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testProps";i:4;s:64:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testSaveOrder";i:4;s:67:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddWithModel";i:4;s:81:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddingToExistingCollection";i:4;s:64:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testCropImage";i:3;s:67:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testIfFilesExist";i:3;}s:5:"times";a:27:{s:59:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testBasicTest";d:0.113;s:80:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testGetShouldReturnEmptyCollection";d:0.011;s:68:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::it_runs_the_migrations";d:0.011;s:85:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_get_should_return_empty_collection";d:0.012;s:62:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testDBRecordTest";d:0.113;s:69:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_record_exist";d:0.109;s:69:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_record_check";d:0.012;s:64:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_avatar_upload";d:0.011;s:60:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_add";d:0.035;s:74:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_record_exist";d:0.016;s:74:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_record_check";d:0.015;s:90:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_get_should_return_empty_collection";d:0.016;s:65:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add";d:0.042;s:69:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_avatar_upload";d:0.015;s:69:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add_one";d:0.108;s:66:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add2";d:0.024;s:62:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddFile";d:0.128;s:77:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddOneFileAsUploadFile";d:0.127;s:86:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddGetDeleteOneFileAsUploadFile";d:0.152;s:77:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddDeleteOneFileAsPath";d:0.06;s:76:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddGetDeleteManyFiles";d:0.12;s:60:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testProps";d:0.039;s:64:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testSaveOrder";d:0.081;s:81:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddingToExistingCollection";d:0.12;s:67:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddWithModel";d:0.231;s:64:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testCropImage";d:0.153;s:67:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testIfFilesExist";d:0.078;}}}
C:37:"PHPUnit\Runner\DefaultTestResultCache":4448:{a:2:{s:7:"defects";a:25:{s:59:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testBasicTest";i:3;s:80:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testGetShouldReturnEmptyCollection";i:4;s:68:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::it_runs_the_migrations";i:3;s:85:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_get_should_return_empty_collection";i:4;s:62:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testDBRecordTest";i:3;s:69:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_record_check";i:4;s:69:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_record_exist";i:4;s:64:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_avatar_upload";i:3;s:60:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_add";i:4;s:90:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_get_should_return_empty_collection";i:4;s:65:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add";i:3;s:74:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_record_exist";i:3;s:74:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_record_check";i:3;s:66:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add2";i:4;s:62:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddFile";i:3;s:77:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddOneFileAsUploadFile";i:4;s:86:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddGetDeleteOneFileAsUploadFile";i:4;s:77:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddDeleteOneFileAsPath";i:4;s:76:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddGetDeleteManyFiles";i:4;s:60:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testProps";i:4;s:64:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testSaveOrder";i:4;s:67:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddWithModel";i:4;s:81:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddingToExistingCollection";i:4;s:64:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testCropImage";i:3;s:67:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testIfFilesExist";i:3;}s:5:"times";a:27:{s:59:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testBasicTest";d:0.113;s:80:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testGetShouldReturnEmptyCollection";d:0.011;s:68:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::it_runs_the_migrations";d:0.011;s:85:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_get_should_return_empty_collection";d:0.012;s:62:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::testDBRecordTest";d:0.113;s:69:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_record_exist";d:0.109;s:69:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_record_check";d:0.012;s:64:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_avatar_upload";d:0.011;s:60:"MonstreX\MediaStorage\Tests\Unit\ExampleTest::test_media_add";d:0.035;s:74:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_record_exist";d:0.016;s:74:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_record_check";d:0.015;s:90:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_get_should_return_empty_collection";d:0.016;s:65:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add";d:0.042;s:69:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_avatar_upload";d:0.015;s:69:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add_one";d:0.108;s:66:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::test_media_add2";d:0.024;s:62:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddFile";d:0.128;s:77:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddOneFileAsUploadFile";d:0.127;s:86:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddGetDeleteOneFileAsUploadFile";d:0.143;s:77:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddDeleteOneFileAsPath";d:0.058;s:76:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddGetDeleteManyFiles";d:0.119;s:60:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testProps";d:0.038;s:64:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testSaveOrder";d:0.078;s:81:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddingToExistingCollection";d:0.119;s:67:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testAddWithModel";d:0.226;s:64:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testCropImage";d:0.149;s:67:"MonstreX\MediaStorage\Tests\Unit\MediaStorageTest::testIfFilesExist";d:0.074;}}}
65 changes: 57 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,89 @@ This package allow you to manage different media files in your project. The pack
## Installing
>composer require monstrex/media-storage
Publish config:
``` bash
$ php artisan vendor:publish --provider="MonstreX\MediaStorage\MediaStorageServiceProvider" --tag="migrations"
$ php artisan vendor:publish --provider="MonstreX\MediaStorage\MediaStorageServiceProvider" --tag="config"
```

>You may use your own way to generate target file names using custom generator in config file:
>'url_generator' => MonstreX\MediaStorage\Services\URLGeneratorService::class,
Make migrations:
``` bash
$ php artisan vendor:publish --provider="MonstreX\MediaStorage\MediaStorageServiceProvider" --tag="config"
$ php artisan vendor:publish --provider="MonstreX\MediaStorage\MediaStorageServiceProvider" --tag="migrations"
$ php artisan migrate
```


## Adding
```php
$user1 = User::find(1);
// Add file from request and bind the file to model using collection name (string)
$collection = Media::add(request()->file('myfile'))->model($user1)->collection('new-gallery')->create();
// Add file from path and disk
$collection = Media::add('images/1.jpg', 'local')->collection('local-file')->create();
// Add file using Collection ID (int)
$collection = Media::model($model)->add($files)->collection(5403)->create();
// Add file with custom properties
$collection = Media::add($file)->props(['title' => 'Novus news','alt' => 'Image #2'])->collection('images')->create();
// Add files using noname collection. You can get collection ID from returned collection - collection_id field.
$collection = Media::add($files)->create();
// Will save original source file as is
$collection = Media::add('images/1.jpg', 'local')->preserveOriginal()->create();
// Will replace target file if exist.
$collection = Media::add($file)->replaceFile()->create();
// Will replace target file name using language table from config file
$collection = Media::add($file)->transliterate('ru')->collection('cyrillic-gallery')->create();
```

## Retrieving
```php
$path = Media::find(1)->path(); // get path by record ID
$path = Media::id(3)->path(); // get path by MEDIA ID
$url = Media::id(3)->url(); // get URL
// Get path by record ID
$path = Media::find(1)->path();
// Get path by MEDIA ID
$path = Media::id(3)->path();
// Get relative URL
$url = Media::id(3)->url();
// Get full URL
$url = Media::id(3)->fullUrl();
// Generate conversion if not exist and return URL
$url = Media::id(3)->crop(250,300)->url();
// Get collection by collection ID
$collection = Media::collection(5403)->get();
// Get collection by collection Name
$collection = Media::model($user1)->collection('new-gallery')->get();
// Get All media entries
$collection = Media::all();
// Get all properties
Media::id(3)->props();
// Get certain propery
Media::id(3)->prop('title');
Media::id(3)->prop('setting.width');
```

## Modify
```php
// Set properties
Media::id(3)->props(['title' => 'New title'])->save();
// Set one property
Media::id(3)->prop('settings.width',500)->save();
// Set order
$collection = Media::collection('new-gallery')->get();
$collection[0]->order(1);
$collection[1]->order(2);
$collection[2]->order(3);
Media::save($collection);
```

## Removing
```php
// Delete one media entry
Media::id(3)->delete();
// Delete whole collection
Media::collection(5403)->delete();
// Delete collection binded to model
Media::model($user1)->collection('new-gallery')->delete()
// Delete All media entries
Media::deleteAll();
```

##API

0 comments on commit ebf5753

Please sign in to comment.