PHP code example of rainetro / laravel-imagebox

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

    

rainetro / laravel-imagebox example snippets


return [
    'disk' => env('IMAGE_BOX_DISK', 'public'),
    'queue_connection_name' => env('QUEUE_CONNECTION', 'sync'),
    'queue_name' => '',
    'model' => \Rainet\ImageBox\Box\Models\Image::class,
    'folder_generator' => \Rainet\ImageBox\Box\FolderGenerator\DefaultFolderGenerator::class,
];

use Illuminate\Database\Eloquent\Model;
use Rainet\ImageBox\ImageBoxInterface;
use Rainet\ImageBox\ImageBoxTrait;

class Post extends Model implements ImageBoxInterface
{
    use ImageBoxTrait;

    //  ...

    public function registerImageCollections(): void
    {
        $this
            ->addImageCollection('image')
            ->acceptsMimeTypes(['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp']);
    }

    public function registerImageCollectionConversions(): void
    {
        $this
            ->getImageCollection('image')
            ->addConversion('thumb')
            ->width(480)
            ->quality(90);

        // $this
        //     ->getImageCollection('image')
        //     ->addConversion('medium')
        //     ->width(600)
        //     ->height(600)
        //     ->quality(90);
    }
}

$post = Post::find(1);
$post
    ->addImage($request->file('image'))
    ->toCollection('image');

$post->load('image');
$post->load('images');
bash
php artisan vendor:publish --provider="Rainet\ImageBox\ImageBoxServiceProvider" --tag="migrations"
php artisan migrate
bash
php artisan vendor:publish --provider="Rainet\ImageBox\ImageBoxServiceProvider" --tag="config"