在干预中,图像源在laravel 8中不可读。我已经尝试检查path是否存在,它确实存在,并尝试重新安装干预,但对laravel仍然不起作用。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
use Intervention\Image\ImageManager;
class PostsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function create()
{
return view('posts.create');
}
public function store()
{
$data = request()->validate([
// 'another' => '',
'caption' => 'required',
'image' => ['required', 'image'],
]);
// open an image file
$image = Image::make(public_path('storage/{$imagePath}'))->fit(1200, 1200);
$image->save();
$imagePath = request('image')->store('uploads', 'public');
auth()->user()->posts()->create([
'caption' => $data['caption'],
'image' => $imagePath,
]);
return redirect('/profile/' . auth()->user()->id);
}
}我不知道是不是public_path或者是什么导致了这里的错误!
发布于 2021-01-26 12:08:29
我尝试了下面的方法,它起作用了。
public function store()
{
$data = request()->validate([
'caption' => 'required',
'image' => ['required', 'image'],
]);
$imagePath = request('image')->store('uploads','public');
//dd($imagePath);
$img = ImageManagerStatic::make(storage_path().'/app/public/'.$imagePath);
$img ->fit(400,400);
$img -> save(storage_path().'/app/public/'.$imagePath);
return redirect('/profile/' . auth()->user()->id);
}https://stackoverflow.com/questions/65700600
复制相似问题