okipa / laravel-medialibrary-ext
Extra features for spatie/laravel-medialibrary package.
Fund package maintenance!
Okipa
Ko Fi
paypal.me/arthurlorent
Installs: 10 810
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 3
Open Issues: 1
Requires
- php: 8.1.*|8.2.*
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-medialibrary: ^10.0
- symfony/mime: ^6.0
Requires (Dev)
- brianium/paratest: ^6.4
- laravel/pint: ^1.1
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^7.0|^8.0
- phpmd/phpmd: ^2.11
- roave/security-advisories: dev-latest
- dev-master
- 10.2.0
- 10.1.0
- 10.0.2
- 10.0.1
- 10.0.0
- 9.2.0
- 9.1.0
- 9.0.0
- 8.1.0
- 8.0.1
- 8.0.0
- 7.19.3
- 7.19.2
- 7.19.1
- 7.19.0
- 7.18.0
- 7.17.3
- 7.17.2
- 7.17.1
- 7.17.0
- 7.16.0
- 7.15.1
- 7.15.0
- 7.14.5
- 7.14.4
- 7.14.3
- 7.14.2
- 7.14.1
- 7.14.0
- 7.13.4
- 7.13.3
- 7.13.2
- 7.13.1
- 7.13.0
- 7.12.2
- 7.12.0
- 7.11.0
- 7.10.0
- 7.9.0
- 7.8.2
- 7.8.1
- 7.8.0
- 7.7.0
- 7.6.9
- 7.6.8
- 7.6.7
- 7.6.6
- 7.6.5
- 7.6.4
- 7.6.3
- 7.6.2
- 7.6.1
- 7.6.0
- 7.5.6
- 7.5.5
- 7.5.4
- 7.5.3
- 7.5.2
- 7.5.1
- 7.5.0
- 7.4.3
- 7.4.2
- 7.4.1
- 7.4.0
- 7.3.12
- 7.3.11
- 7.3.10
- 7.3.9
- 7.3.8
- 7.3.7
- 7.3.6
- 7.3.5
- 7.3.4
- 7.3.3
- 7.3.2
- 7.3.1
- 7.3.0
- 7.1.8
- 7.1.7
- 7.1.6
- 7.1.5
- 7.1.4
- 7.1.3
- 7.1.2
- 7.1.1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.9.0
- 3.8.0
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.1
- 3.5.0
- 3.4.0
- 3.3.1
- 3.3.0
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.1
- 3.0.0
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- 0.1.0
This package is auto-updated.
Last update: 2024-11-19 23:36:50 UTC
README
This package extension provides extra features for the spatie/laravel-medialibrary package.
Found this package helpful? Please consider supporting my work!
Compatibility
This package extension will follow the base package major versions but may be a bit stricter about compatibility constraints.
Upgrade guide
Table of contents
- Installation
- Documentation
- Translations
- Extension features
- Testing
- Changelog
- Contributing
- Security
- Credits
- Licence
Installation
First, be sure to follow the base package installation instructions:
- https://github.com/spatie/laravel-medialibrary#installation
- https://docs.spatie.be/laravel-medialibrary/v8/installation-setup
Then, install the extension via composer:
composer require okipa/laravel-medialibrary-ext
Finally, implement the ExtendsMediaAbilities
trait to be able to use the extension features in addition of the base package ones.
use Illuminate\Database\Eloquent\Model; use Okipa\MediaLibraryExt\ExtendsMediaAbilities; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class Page extends Model implements HasMedia { use InteractsWithMedia; use ExtendsMediaAbilities; // ... }
Documentation
Find the complete documentation of the base package here: https://docs.spatie.be/laravel-medialibrary/v8/introduction.
Translations
All captions are translatable.
See how to translate them on the Laravel official documentation: https://laravel.com/docs/localization#using-translation-strings-as-keys.
Here is the list of the sentences available for translation:
Min. width: :width px.
Min. height: :height px.
{1}Accepted type: :types.|[2,*]Accepted types: :types.
Max. file size: :size Mb.
Extension features
Media validation rules
Declaring your media validation rules like this:
// In your user storing form request for example public function rules() { return [ 'avatar' => (new User)->getMediaValidationRules('avatar'), // your other validation rules ]; }
Will generate:
// Example ['mimetypes:image/jpeg,image/png', 'mimes:jpg,jpeg,jpe,png', 'dimensions:min_width=60,min_height=20', 'max:5000'];
Available public methods:
->getMediaValidationRules(string $collectionName): array
: returns all the validation rules for the given collection.->getMediaMimesValidationRules(string $collectionName): string
: returns only the mimes validation rules for the given collection.->getMediaMimeTypesValidationRules(string $collectionName): string
: returns only the mime types validation rules for the given collection.->getMediaDimensionValidationRules(string $collectionName): string
: returns only the dimension validation rules for the given collection.->getMediaSizeValidationRule(): string
: returns only the max file size validation rule set from the base packagemedia-library.max_file_size
configuration value.
Media caption
Adding a constraint caption under a file input:
<!-- In your HTML form --> <label for="avatar">Choose a profile picture:</label> <input type="file" id="avatar" name="avatar" value="{{ $user->getFirstMedia('avatar')->name }}"> <small>{{ $user->getMediaCaption('avatar') }}</small>
Will generate:
<!-- Example -->
Min. width: 150 px. Min. height: 70 px. Accepted types: jpg, jpeg, jpe, png. Max file size: 5Mb.
Available public methods:
getMediaCaption(string $collectionName): string
: returns a complete caption for the given collection.getMediaDimensionsCaption(string $collectionName): string
: returns only the dimensions caption for the given collection.getMediaMimeTypesCaption(string $collectionName): string
: returns only the mime types caption for the given collection.getMediaSizeCaption(): string
: returns only the config max file size caption only.
Exceptions
In order to avoid careless mistakes when using public methods that are requiring a string $collectionName
argument provided by this extension, an Okipa\MediaLibraryExt\Exceptions\CollectionNotFound
exception will be thrown when the given collection name is not found in the targeted model.
Testing
composer test
Changelog
Please see CHANGELOG for more information about what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email arthur.lorent@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.