I'm trying to check if the file exists to delete it when the post is deleted but it's never finding it.
If I change the Storage::exists() for Storage::get() just to check, I get the File Not Found Exception with the path C:/xampp/htdocs/cms/blog/public/images/apple.jpg which I can see the picture if I put in the browser.
Store function on PostController
public function store(CreatePostRequest $request)
{
$input = $request->all();
if ($file = $request->file('file')) {
//
$name = $file->getClientOriginalName();
$file->move(public_path('images/'), $name);
$input['path'] = $name;
}
$new_post = Post::create($input);
return redirect(route('post.show', $new_post->id));
}
Destroy function on PostController
public function destroy($id)
{
$post = Post::findOrFail($id);
if (Storage::exists(public_path('images/') . $post->path))
Storage::delete(public_path('images/') . $post->path);
$post->delete();
return redirect(route('posts.index'));
}
I also have this on my filesystems.php
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('images') => storage_path('app/images'),
],
I can easily show the image in blade with just src="{{'/images/' . $post->path}}"