BinaryFileResponse in Laravel undefined
我遇到了以下问题:我想在路由/getImage/{id}上返回图像,该函数如下所示:
public function getImage($id){
$image = Image::find($id);
return response()->download('/srv/www/example.com/api/public/images/'.$image->filename);
}
当我这样做时,它会返回我:
FatalErrorException in HandleCors.php line 18:
Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::header()
我已经在控制器的开头。我不认为HandleCors.php是问题所在,但无论如何:use Response;
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Http\Response;
class CORS implements Middleware {
public function handle($request, Closure $next)
{
return $next($request)->header('Access-Control-Allow-Origin' , '*')
->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application');
}
}
我实际上不知道为什么会发生这种情况,因为它与Laravel Docs中描述的完全一样。当我遇到错误时,我已经更新了Laravel,但这并没有解决它。