在laravel 5上尝试编码图像时出错

时间:2016-06-18 19:31:29

标签: image laravel intervention

我安装"作曲家需要干预/图像" ... 在config / app.php上添加

提供者:Intervention \ Image \ ImageServiceProvider :: class, 别名:'图像' =>干预\图片\外墙\图片::类,

然后在我的路线上我有这个:

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

在我的ThreadController.php上:

进口:

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

功能:

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;
}

收到此错误:

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

编辑:从这个网站http://www.core45.com/using-database-to-store-images-in-laravel-5-1/得到了例子,我有什么遗失的吗?

1 个答案:

答案 0 :(得分:0)

我解决了它,编码我的课而不是图像,它是

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