0

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

1 Answer 1

0

Try this

<img src="{{asset(Storage::disk('local')->url($post->image))}}"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.