Download the PHP package yoelpc4/laravel-media without Composer
On this page you can find all versions of the php package yoelpc4/laravel-media. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-media
Laravel Media
Laravel Media manager.
Requirement
Install
Require this package with composer via command:
Package Publication
Publish package configuration via command:
Publish package migrations via command:
Publish package resources via command:
Configure
Image Optimizers
By default, all images added to the media will be optimized according to image_optimizers
on the media config. For
more information visit https://github.com/spatie/image-optimizer#optimization-tools.
Media Model
Customize media model by extending \Yoelpc4\LaravelMedia\Models\Media
, then register your model on model
option.
Media Observer
Customize media observer by extending \Yoelpc4\LaravelMedia\Observers\MediaObserver
, then register your observer
on observer
option.
Versioned URL
Generate media URL with version on query params i.e: http://localhost/storage/1/image.jpg?v=1610970549 by setting versioned_url
option to true.
Mediable Model
Mediable Contract and InteractsWithMedia Concern
The model that has media must implement \Yoelpc4\LaravelMedia\Contracts\Mediable
interface and
use \Yoelpc4\LaravelMedia\Concerns\InteractsWithMedia
trait.
Example Mediable Contract and InteractsWithMedia Concern usage with profileImage relationship on User model
Media Group Registration
Example register the media group on your mediable model on Project model
Media Conversion Registration
Example register the media conversion on media group registration on User model
Media Group
The media group has name, mime types, max file size, max file limit & media conversions registration properties. It consists of one file or many files. The mime types, max file size, max file limit properties will be used on validation when adding file to the media. The default media group has empty array mime types, 2MB max file size, & null max file limit.
If media group has max file limit with integer data type (other than null), this package will keep last of max file limit file(s) on disk and remove the other file(s). For example User model has profile image media group with max file limit 1, and we have an user id 1 has a profile image as media id 1 on database. If we try to upload a profile image on user id 1, then media id 1 and old profile image will be deleted and user id 1 ends up with media id 2 and new profile image.
Media Conversion
The media conversion has name, manipulations, and should be performed on media group properties.
It is intended to the media with file type image.
You can call \Spatie\Image\Manipulations
methods on media conversion registration because it has __call
magic method, the proxied method call will be registered as it's manipulations.
Add Media File to Mediable
Add Media File from Path
Example add a media file from storage path to the first User model on database
Add Media File from Uploaded File
Example add a media file from \Illuminate\Http\UploadedFile
to the unsaved Project model
Media URL Generation
Get Media URL
Example get media url on media
Get Media Conversion URL
Example get media conversion url on related media
If the media doesn't have the specified media conversion name it'll return null.
Difference From spatie/laravel-medialibrary
Media Group vs Media Collection
laravel-media use media group as the term of similar media type, while laravel-medialibrary use media collection as the term.
Mandatory Media Group
laravel-media require you to add file to the named media group on mediable model. While laravel-medialibrary offers flexibility to omit media group name and gives you "default" as media group name.
Validation Exception
laravel-media always perform validation based on registered media group's mime types and max file size, the \Illuminate\Validation\ValidationException
will be thrown when validation is unmet.
On the other hand laravel-medialibrary throws \Spatie\MediaLibrary\MediaCollections\Exceptions\FileUnacceptableForCollection
instead of \Illuminate\Validation\ValidationException
.
Add File to Unsaved Mediable Model
laravel-media allows you to add media file to the unsaved mediable model. While laravel-medialibrary expects every media must be attached to the saved mediable model.
For more information see issues here:
- https://github.com/spatie/laravel-medialibrary/issues/343
- https://github.com/spatie/laravel-medialibrary/issues/1060
- https://github.com/spatie/laravel-medialibrary/issues/1384
- https://github.com/spatie/laravel-medialibrary/issues/1423
- https://github.com/spatie/laravel-medialibrary/issues/1444
Also the pull request here:
File source
laravel-media only allows you to add file from disk path and uploaded file. While laravel-media allows you to add file from disk path, remote file, uploaded file, symfony file, temporary upload, url, & request.
Comprehensive vs Narrow Solution
laravel-media offers you narrow solution with limited features for specific requirements (validation exception, unsaved mediable model, & simple file source). While laravel-medialibrary offers you comprehensive solution with rich features and battle tested. So consider carefully prior to install this package.
License
The Laravel Media is open-sourced software licensed under the MIT license.
All versions of laravel-media with dependencies
ext-fileinfo Version *
illuminate/contracts Version 8.*|7.*|6.*
illuminate/database Version 8.*|7.*|6.*
illuminate/http Version 8.*|7.*|6.*
illuminate/support Version 8.*|7.*|6.*
illuminate/validation Version 8.*|7.*|6.*
spatie/image Version ^1.10.1
spatie/temporary-directory Version ^1.3.0