코드만 써주셔서는 문제를 해결을 위한 힌트를 얻을 수 없습니다. 문제가 발생했을 때 storage/logs/laravel.log 에 찍힌 마지막 예외 트레이스를 올려주시면 답변하는데 도움이 될 듯 합니다. 예외 트레이스는 대략 아래와 같이 생겼습니다.
[2018-04-21 15:57:48] local.ERROR: ErrorException: array_reduce() expects parameter 1 to be array, object given in /var/www/html/ClassName.php:72 Stack trace: #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'array_reduce() ...', '/var/www/html/c...', 72, Array) #1 /var/www/html/ClassName.php(72): array_reduce(Object(Illuminate\Support\Collection), Object(Closure), 0) # ...
답변해주셔서 감사합니다. 이미지 요청 URL 후 이런 로그가 남아 있었습니다.
[2018-04-21 14:25:21] production.ERROR: GD Library extension not available with this PHP installation. {"exception":"[object] (Intervention\\Image\\Exception\\NotSupportedException(code: 0): GD Library extension not available with this PHP installation. at /home/fineweather/myapp/vendor/intervention/image/src/Intervention/Image/Gd/Driver.php:16)
[stacktrace]
#0 /home/fineweather/myapp/vendor/intervention/image/src/Intervention/Image/ImageManager.php(108): Intervention\\Image\\Gd\\Driver->__construct()
#1 /home/fineweather/myapp/vendor/intervention/image/src/Intervention/Image/ImageManager.php(50): Intervention\\Image\\ImageManager->createDriver()
#2 /home/fineweather/myapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Intervention\\Image\\ImageManager->make('/home/fineweath...')
20.2 이미지 응답 부분인데..
============= DocsController =============
public function show($file = null)
{
$index = \Cache::remember('docs.index', 120, function() {
return markdown($this->docs->get());
});
$content = \Cache::remember("docs.{$file}", 120, function() use ($file) {
return markdown($this->docs->get($file ?: 'installation.md'));
});
return view('docs.show', compact('index', 'content'));
}
public function image($file)
{
$image = $this->docs->image($file);
return response($image->encode('png'), 200, [
'Content-Type' => 'image/png',
]);
}
==============web.php=================
Route::get('docs/{file?}','DocsController@show');
Route::get('docs/images/{image}', 'DocsController@image');
============ Documentation.php =============
public function get($file = 'documentation.md')
{
$content = File::get($this->path($file));
return $this->replaceLinks($content);
}
public function image($file)
{
return \Image::make($this->path($file, 'docs/images'));
}
protected function path($file, $dir = 'docs')
{
$file = ends_with($file,['.md', '.png']) ? $file : $file . '.md';
$path = base_path($dir . DIRECTORY_SEPARATOR . $file);
if (! File::exists($path)) {
abort(404,"요청하신 파일이 없습니다.");
}
return $path;
}
protected function replaceLinks($content)
{
return str_replace('/docs/{{version}}','/docs', $content);
}
이런식으로 오류가 뜹니다..
GET http://localhost:8000/docs/images/foo-img-01.png 400 (Bad Request)
먼저, 사진은 프로젝트 폴더의 /docs/images 폴더에 있습니다.
더욱 이 문제가 show() 함수 까지는 잘 호출이 되는데,
web.php 의 /docs/foo-img-01.png 이 url 로 요청시
image() 함수 자체가 호출이 안되는것 같아요. image() 함수 안에서 echo 로 문자열 찍어 봤는데 안 뜹니다.
/docs/images/{image} 요청은 어디서 이루어지는거고,
image() 함수는 왜 호출이 안 될까요, 그리고 왜 제대로 사진이 안 뜰까요??
피드백 해주시면 감사하겠습니다.