PHP code example of mr-timofey / laravel-aio-images

1. Go to this page and download the library: Download mr-timofey/laravel-aio-images 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/ */

    

mr-timofey / laravel-aio-images example snippets


// add relation to a table
/** @var Illuminate\Database\Schema\Blueprint $table */
$table->string('avatar_image_id')->nullable();
$table->foreign('avatar_image_id')
	->references('id')
	->on('aio_images')
	->onDelete('set null');


// add relation to a model
public function avatarImage()
{
	$model->belongsTo(ImageModel::class, 'avatar_image_id');
}


// create pipe config in config/aio_images.php
[
	// ...
	'pipes' => [
		// /storage/images/avatar/image-id.jpg
		'avatar' => [
			// $interventionImage->fit(120)
			['fit', 120],
			// $interventionImage->greyscale()
			['greyscale']
		]
	]
];

// display original avatar
echo '<img src="' . route('aio_images.original', ['image_id' => $model->avatar_image_id]) . '" alt="Original avatar" />';
// display 120x120 squared grey colored avatar
echo '<img src="' . route('aio_images.pipe', ['pipe' => 'avatar', 'image_id' => $model->avatar_image_id]) . '" alt="Processed with pipe [avatar]" />';

// same with ImageModel instance
echo '<img src="' . $image->getPath() . '" alt="Original avatar" />';
echo '<img src="' . $image->getPath('avatar') . '" alt="Processed with pipe [avatar]" />';


// upload image manually from any of your custom controllers

use Illuminate\Http\Request;
use MrTimofey\LaravelAioImages\ImageModel;

function upload(Request $req)
{
	return ImageModel::upload($req->file('image'));
}

bash
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
php artisan vendor:publish --provider="MrTimofey\LaravelAioImages\ServiceProvider"
php artisan migrate
bash
php artisan storage:link