【问题标题】:Getting error on laravel 5 trying to encode an imagelaravel 5 尝试编码图像时出错
【发布时间】:2016-06-18 19:31:29
【问题描述】:

我安装了“作曲家需要干预/图像”... 添加到 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/ 获得示例,我有什么遗漏吗?

【问题讨论】:

  • 你为什么要在你的模型上调用encode
  • ??它是我的 threadController 中的一个函数,我发布了它:S
  • 你在你的模型上调用encode$thread = Thread::findOrFail($id); 是模特。 $thread->encode('jpeg'); 在你的模型上调用 encode
  • 我在这个网站上的例子core45.com/using-database-to-store-images-in-laravel-5-1他也在控制器上做:S,不正确?

标签: image laravel intervention


【解决方案1】:

我解决了,正在编码我的类而不是图像,它是

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

【讨论】:

    猜你喜欢
    • 2013-02-23
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    相关资源
    最近更新 更多