laravel 5 尝试对图像进行编码时出错
Getting error on laravel 5 trying to encode an image
我安装了"composer require intervention/image"...
添加于 config/app.php
提供商:Intervention\Image\ImageServiceProvider::class,
别名:'Image' => Intervention\Image\Facades\Image::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/ 得到了示例,我是否遗漏了什么?
我解决了,正在编码我的 class 而不是图像,它是
$response = Response::make($imagen->编码('jpeg'));
我安装了"composer require intervention/image"... 添加于 config/app.php
提供商:Intervention\Image\ImageServiceProvider::class, 别名:'Image' => Intervention\Image\Facades\Image::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/ 得到了示例,我是否遗漏了什么?
我解决了,正在编码我的 class 而不是图像,它是
$response = Response::make($imagen->编码('jpeg'));