PHP code example of ziffmedia / laravel-eloquent-imagery

1. Go to this page and download the library: Download ziffmedia/laravel-eloquent-imagery 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/ */

    

ziffmedia / laravel-eloquent-imagery example snippets


// in a table migration
$table->json('image')->nullable();

use ZiffMedia\LaravelEloquentImagery\Eloquent\HasEloquentImagery;

class Post extends Model
{
    use HasEloquentImagery;

    protected $eloquentImagery = [
        'path' => 'posts/{id}.{extension}',
    ];
}

use ZiffMedia\LaravelEloquentImagery\Eloquent\HasEloquentImagery;

class Post extends Model
{
    use HasEloquentImagery;

    protected $eloquentImagery = [
        'images' => [
            'path' => 'post/{id}/image-{index}.{extension}',
            'collection' => true
        ],
    ];
}

@if($bam->image->exists)
    <img src="{{ $bam->image->url() }}" width="20" />
@endif

@if($bam->image->exists)
    <img src="{{ $bam->image->url('size200x200|trim) }}" width="20" />
@endif