Sociopath
Sociopath

Reputation: 295

Getting error on laravel 5 trying to encode an image

I installed "composer require intervention/image"... added on config/app.php

providers: Intervention\Image\ImageServiceProvider::class, aliases: 'Image' => Intervention\Image\Facades\Image::class,

then on my routes I have this:

Route::get('/thread/{img}', 'ThreadController@mostrarImagen');

on my ThreadController.php:

Imports:

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Thread;
use App\Subboard;
use Image;
use Illuminate\Support\Facades\Response;

Function:

public function mostrarImagen($id) {
    $thread = Thread::findOrFail($id);
    $imagen = Image::make($thread->thrImg);
    $response = Response::make($thread->encode('jpeg'));
    $response->header('Content-Type', 'image/jpeg');
    return $response;
}

getting this error:

BadMethodCallException in Builder.php line 2345: Call to undefined method Illuminate\Database\Query\Builder::encode()

EDIT: got the example from this website http://www.core45.com/using-database-to-store-images-in-laravel-5-1/, is there something i'm missing?

Upvotes: 0

Views: 560

Answers (1)

Sociopath
Sociopath

Reputation: 295

I solved it, was encoding my class instead of the image, it was

$response = Response::make($imagen->encode('jpeg'));

Upvotes: 0

Related Questions