PHP code example of escapework / laramedias

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();

<img src="{{ media_path($banner, 'banner', 1920, 400, 'crop') }}" alt="...">

use EscapeWork\LaravelSteroids\Presenter;

class BannerPresenter extends Presenter
{
    public function banner($w = 100, $h = 50, $fit = 'fit')
    {
        return media_path($this->model, 'banner', $w, $h, $fit);
    }
}

    <img src="{{ $banner->present->banner(1920, 500, 'crop') }}">

$ php artisan vendor:publish --provider="EscapeWork\LaraMedias\Providers\MediasServiceProvider"
$ php artisan migrate