ฉันต้องการใช้ Glide สำหรับแหล่งที่มาของภาพทั้งหมดของฉัน
ตามคำแนะนำนี้ ฉันสามารถรับภาพที่ http://myweb.dev/img/test.jpg?w=200&filt=sepia
เส้นทาง:
Route::get('/img/{path}', 'ImageController@show')->where('path', '.*');
ตัวควบคุม:
namespace App\Http\Controllers;
use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;
class ImageController extends Controller
{
public function show(Filesystem $filesystem, $path)
{
$server = ServerFactory::create([
'response' => new LaravelResponseFactory(app('request')),
'source' => $filesystem->getDriver(),
'cache' => $filesystem->getDriver(),
'cache_path_prefix' => '.cache',
'base_url' => 'img',
]);
return $server->getImageResponse($path, request()->all());
}
}
เนื่องจากรูปภาพทั้งหมดของฉันเป็นไดเร็กทอรี /public/uploads ฉันจึงเปลี่ยนดังต่อไปนี้
เส้นทาง:
Route::get('uploads/{path}', 'ImageController@show')->where('path', '.*');
คอนโทรลเลอร์
public function show(Filesystem $filesystem, $path)
{
$server = ServerFactory::create([
'response' => new LaravelResponseFactory(app('request')),
'source' => public_path(),
'cache' => public_path(),
'cache_path_prefix' => '.cache',
'base_url' => 'uploads',
]);
return $server->getImageResponse($path, request()->all());
}
เมื่อฉันไปที่ http://myweb.dev/uploads/test.jpg?w=200&filt=sepia ฉันได้ภาพที่ไม่มีการเปลี่ยนแปลงใดๆ หรือไดเร็กทอรี .cache ใดๆ ถูกสร้างขึ้น
ฉันลอง base_path()
และ /uploads
เช่นกัน แต่ก็ไม่ได้ผลเช่นกัน ฉันใช้ไดเรกทอรีอัพโหลดสำหรับ elfinder
ฉันทำอะไรผิดที่นี่?