Download the PHP package escapework/laramedias without Composer
On this page you can find all versions of the php package escapework/laramedias. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download escapework/laramedias
More information about escapework/laramedias
Files in escapework/laramedias
Package laramedias
Short Description A Laravel package that integrates Glide for easily manage medias on your project.
License MIT
Informations about the package laramedias
A Laravel package that integrates [Glide](http://glide.thephpleague.com) and easy media management on your Laravel project.
Version Compatibility
Laravel | Laramedias | ||
---|---|---|---|
9.0.x | 0.9.x | ||
5.5.x | 5.6.x | 5.7.x | 0.7.x |
5.4.x | 0.6.x | ||
5.4.x | 0.5.x | ||
5.3.x | 0.4.x | ||
5.2.x | 0.3.x | ||
5.1.x | 0.2.x |
Installation
Via Composer:
Configuration
And execute the following code:
Configurations explained:
Usage
This package allows you to easily use medias with your laravel models. There are two basic ways to use:
One model has multiple medias
Let's say you have a Product
model that need to have multiple medias. You have to do this:
- Import the following trait in your model;
Now, you can do this:
Upload and create multiple medias:
Interate through your medias
The $product->medias
will be a default Laravel collection of EscapeWork\LaraMedias\Models\Media
models which you can use any of the collection methods available.
Each $media
object will be a LaraMedias\Models\Media
eloquent model, which will have a presenter for easily displaying images (see the above example).
The parameters in the example are the Glide width (w
), height (h
) and fit
. You can see a simple example here (http://glide.thephpleague.com/1.0/simple-example/).
If your model was deleted, all the medias will be deleted too.
Deleting medias
For delete your medias, just call the method removeMedias
.
For removing all medias, just call the removeMedias
method without any parameters.
Events
These events are dispatched when in the above use case:
Action | Event |
---|---|
EscapeWork\LaraMedias\Models\Media::created | EscapeWork\LaraMedias\Events\MediaAdded |
EscapeWork\LaraMedias\Models\Media::updated | EscapeWork\LaraMedias\Events\MediaUpdated |
EscapeWork\LaraMedias\Models\Media::deleted | EscapeWork\LaraMedias\Events\MediaDeleted |
One model has one media field
Let's say you have a Banner
model and want to upload a single image for him. With Laramedias
you can do this:
First, configure the config/medias.php
file:
Second, use the EscapeWork\LaraMedias\Traits\Medias
trait in your Banner
model.
Then, you can just use the uploadSingleMedia
method.
After that, you can just use the media
helper method to show your banner.
I would also recomend in this case to make use of Presenters. You can use your custom setup or make use of this package that makes it very easy.
Then, you can setup like this:
And you like this:
Contributing
Feel free to open any pull request/issue with your idea/bug/suggestion.
License
See the License file.