PHP code example of levoolabs / imageable

1. Go to this page and download the library: Download levoolabs/imageable 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/ */

    

levoolabs / imageable example snippets


$topic = Topic::where('name', 'Awsome topic')->first();
echo $topic->image->s; // Small image url
echo $topic->image->m; // Medium image url
echo $topic->image->l; // Large image url
echo $topic->image->o; // Original image url

foreach ($product->secondary_images as $image) {
    echo $image->s;
}

if ($topic->has_image) {
    //
}

public function uploadImageAjax(Request $request, Topic $topic)
{
    if ($request->ajax()) {
        $image = $topic->store_image($request->file('file'));
        return response()->json(['ok' => $image->id], 200);
    }
    abort(404);
}

$topic->delete_image();

Schema::create('images', function(Blueprint $table) {
    $table->increments('id');
    $table->integer('imageable_id')->unsigned();
    $table->string('imageable_type');
    $table->string('image_type');
    $table->string('image_path'); #NOTE relative filename with extension -> /folder/folder/filename.ext
    $table->timestamps();
});

class Topic extends Model
{
    use \LevooLabs\Imageable\Traits\SingleImageableTrait;
    
    protected $table = 'topics';
    
    protected $fillable = [
        'title'
    ];
    
}

class Product extends Model
{
    use \LevooLabs\Imageable\Traits\MultiImageableTrait;

    public $template_base_name = "product";
    
    protected $image_type = MyConstants\ImageType::PRODUCT_MAIN;
    protected $secondary_image_type = MyConstants\ImageType::PRODUCT;

    protected $default_image_name = "product.jpg";
    
    protected $extension = "jpg";

    /* ... */
}

    'product'   => \App\ImageFilters\Product\Upload::class,
    'product-s' => \App\ImageFilters\Product\Small::class,
    'product-m' => \App\ImageFilters\Product\Medium::class,
    'product-l' => \App\ImageFilters\Product\Large::class,