Reputation: 17
am new to Laravel 8, I created a controller called PostsController and I have a file called create.blade.php which has a form with input entry and an image, after filling an entry and choosing an image , the image is supposed to be displayed in index.blade.php but I get an error that Intervention\Image\Exception\NotReadableException Image source not readable but the image get saved in the folder
here is my PostsController
<?php
namespace App\Http\Controllers;
use Intervention\Image\Facades\Image;
use Illuminate\Http\Request;
class PostsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function create(){
return view('posts.create');
}
public function store(){
$data = request()->validate([
'caption' => 'required',
// 'another' => '',
// 'image' => 'required|image',
'image' => ['required','image']
]);
$imagePath = (request('image')->store('uploads','public'));
$image =
Image::make(public_path("storage/app/public/uploads/{$imagePath}"))->fit(100,100);
$image->save();
auth()->user()->posts()->create([
'caption' => $data['caption'],
'image' => $imagePath,
]);
\App\Models\Post::create($data);
dd(request()->all());
return redirect('/profile/'. auth()->user()->id);
}
public function show(\App\Models\Post $post){
return view('posts.show', compact('post'));
}
}
here is my index.blade.php
Upvotes: 1
Views: 263
Reputation: 321
Image::make(public_path("storage/app/public/uploads/{$imagePath}"))->fit(100,100);
This line uses public_path
which refers to your public
folder, so you're looking for the image inside public/storage/app/public/uploads/...
instead of storage/app/public/uploads/...
.
You should be using storage_path
(see https://laravel.com/docs/9.x/helpers#method-storage-path)
Considering what I said, you'd be doing something like
Image::make(storage_path("app/public/uploads/{$imagePath}"))->fit(100,100);
Upvotes: 2