Download the PHP package nh/mediable without Composer
On this page you can find all versions of the php package nh/mediable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mediable
Installation
Install the package via composer:
Publish the config and the Media model:
If you need to publish the database you can use:
To make a model mediable, add the Mediable trait to your model:
You can retrieve the media (order by a position) of a model:
Or you can retrieve the first media of a model:
Retrieve all media by a type:
You can check if a model has some media:
If you need to resize the picture media (JPEG/PNG), add the sizes in the config mediable.php at 'sizes':
If you need to add a watermark you can activate the functionnality in the config mediable.php, add the sizes in the config mediable.php at 'sizes':
By default the media are upload in the public disk, but you can change this in the config mediable.php.
The media are saved in:
- A folder with the model classname in plural (exemple: App\Post => posts)
- A folder with the media format name in plural (exemple: 42.jpg => images)
- For the images, a folder with the resize value (exemple: 42.jpg which is resized with a 100px height => h-100)
Views
Add a media
The names of the inputs must be: media_to_add[KEY][name] and media_to_add[KEY][file] and in option you can add media_to_add[KEY][position]
Edit a media
The name of the input must be: media_to_update[KEY][name] and in option you can add media_to_update[KEY][position]
Delete a media
The name of the input must be: media_to_delete[] and the value must be the ID
Model
Attributes
You can retrieve the filename of a media Return: 42.jpg
You can retrieve the base folder of a media Return: posts
You can retrieve the folder of a media Return: posts/images
You can retrieve the format of a media The format is defined by the extension, exemple a .jpg will return 'image'
You can retrieve the default url of a media Return: posts/images/42.jpg
You can retrieve the url of a the thumbnail of a media (Only if the format is 'image') Return: posts/images/thumbnails/42.jpg
Function
You can retrieve the url of a media, and you can add a subfolder. Exemple: 42.jpg which is resized with a 100px height => 'posts/images/h-100/42.jpg'
You can retrieve the absolute url of a media from the server, and you can add a subfolder. Exemple: 42.jpg which is resized with a 100px height => '/Users/YOURUSERNAME/Web/MYPROJECT/public/storage/FOLDER/images/SUBFOLDER/42.png'
You can retrieve the file of a media, and you can add a subfolder. Exemple: 42.jpg which is resized with a 100px height => 'posts/images/h-100/42.jpg'
Events
You can use the MediaEvent for dispatch events that happen to the media. You can pass a name, the parent model, the media model (or null) and the number of media affected