trying to upload an image through a post Form: this is my controller:
public function store(Request $request)
{
$request->validate([
'title'=>'required',
'content'=>'required',
'image'=>'required',
'description'=>'required'
]);
$image = $request->image->store('images');
Post::create([
'title' => $request->input('title'),
'content' => $request->input('content'),
'description' => $request->input('description'),
'image' => $image
]);
return redirect(route('posts.index'))->with('success', 'Posts Submitted successfully');
}
I used : php artisan storage:link which generated a folder named images in public directory: Absolute path is: C:\xampp\htdocs\blogPholio\public\storage\images\KWDKRrty2ijXjrgrismvyiV4k6UAQNrFogJl9W2f.jpeg
in my blade I am trying to show image through/:
<img src="{{Storage::url($post->image)}}">
My form in the create blade looks like:
<form action="{{ route('posts.store') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Image:</strong>
<input type="file" name="image" class="form-control" placeholder="upload:">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Add</button>
</div>
</div>
</form>
Thanksa lot