1. Go to this page and download the library: Download escapework/laramedias library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
escapework / laramedias example snippets
<img src="{{ $product->present->picture(500, 300, 'crop') }}" alt="Easy media management">
'disk' => null, // if you dont want to use filesystems.default disk config, change it here...
// ...for saving on another disk
'max_size' => [
'width' => 2000, // when creating medias, the images will be resized to this max_size...
'height' => 2000, // ...for reducing disk usage
],
'url' => 'medias', // if you want to change the laravel glide medias URL
'dir' => 'medias', // if you want to change the default directory where the medias are saved
'path' => 'general', // if you want to change the directory where the multipleMedias are saved (you will undestand this later)
use EscapeWork\LaraMedias\Traits\Medias;
class Product extends Model
{
use Medias;
}
$product->uploadMedias($request->file('medias'));
@foreach ($product->medias as $media)
/*
all media models have an presenter class so you can easily show the image in different forms
->picture($width, $height, $fit)
*/
$product->removeMedias([1, 2]); // just pass the IDs
$product->removeMedias();
'models' => [
'banners' => [
'model' => 'App\Models\Banner',
'fields' => ['banner'] // here you have to put the fields in your model which use medias
],
],
use EscapeWork\LaraMedias\Traits\Medias;
class Banner extends Model
{
use Medias;
}
$banner = Banner::find(1);
$banner->uploadSingleMedia($request->file('banner'), 'banner'); // the second parameter is the field name to be updated
$banner->save();