0
votes

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?

1
why are you calling encode on your model?lagbox
?? its a function inside my threadController i posted it :SSociopath
You are calling encode on your model. $thread = Thread::findOrFail($id); is a model. $thread->encode('jpeg'); is calling encode on your model.lagbox
i ght the example from this website core45.com/using-database-to-store-images-in-laravel-5-1 he does it on the controller too :S, it's not correct?Sociopath

1 Answers

0
votes

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

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