Download the PHP package yektadg/medialibrary without Composer
On this page you can find all versions of the php package yektadg/medialibrary. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yektadg/medialibrary
More information about yektadg/medialibrary
Files in yektadg/medialibrary
Package medialibrary
Short Description simple library for handling medias for projects
License
Informations about the package medialibrary
laravel-media-library
MediaLibrary is a laravel library for handling images in laravel projects . You can upload your images , modify their alt , categorize them into the folders and etc. It also compress your images to 4 different sizes and keeps the original size , so you can access them in client side based on user screen or use it with lazy loading .
Screenshots
Installation
You can install the package via composer:
Once installed, you should publish the provided assets to create the necessary migration and config files.
Requirements
Usage
Just add the following line at the end of your laravel blade after all javascript codes .
If you want to just access the media library view for using alongside your customized view you can use the following line .
If you want to use both on the same page beware of id conflict between them .
Then you must add class to your html button to open the library .
You can use MediaLibrary for different use types ( you can view all usage under this section ) , so you should specify it when defining button .
Sample of defining MediaLibrary for usage :
In above code after clicking on Upload Images
MediaLibrary pops up and after selecting images , they will be stored in
the hidden input with html id image-holder-1
.
The three first attributes are MediaLibrary attributes .you can see all of MediaLibrary attributes in the below section .
Attributes
MediaLibrary uses different html attributes on html elements (like buttons,anchor and ...) to handle different situation .
You can see list of attributes below :
Attribute | Description |
---|---|
useType |
Defines the type of element for usage (for now 3 types are supported : hidden , imagePreview , tinymce ) |
multipleSelect |
Allows MediaLibrary to select multiple images for use (like when you use tinymce) |
useId |
Refers the html element that holds the images |
Note : All attributes and their values are case-sensitive
Features
Limiting Access To Medias
You can limit access to medias by adding accessAllMedia
attribute to the Request
using laravel middleware.
Here is the example how to do it :
- First make a middleware with laravel command
php artisan make:middleware CheckAccessMedia
- Register your middleware in
kernel.php
at$routeMiddleware
array inHttp
folder of your project'CheckMediaAccess' => CheckMediaAccess::class
- Then add the alias of your middleware in
middleware
array inmedialibray.php
at config folder of your project in this case'CheckMediaAccess'
- Edit your newly created middleware and add your condition for example :
In above example user with id of 1
can access all of uploaded medias but all other users can only access their medias.
Lazy Loading
MediaLibrary generates images in 4 different size , you can use them for lazy loading . Below code loads images based on user screen size :
Note : you need to define imageExistRoute
before above codes;
Then you can use lazy loading by adding resizing
class and originalSrc
attribute to your html image tag .
Note : default image should have low disk size and be a constant image for all pages
Language
You can edit toast.blade.php
for changing toast header in resources/views/vendor/yektadg/medialibrary
.
For changing toast messages edit mlLang.js
in public/vendor/yektadg/medialibrary
.