vendredi 27 mars 2020

Image not displaying in view. from database

In my laravel project I tried to load images from database. But it displays the broken link. But when I inspect the image it shows the link. But when i clicked the link it shows 404 error..... this is my codes

this is the code of view .............

@extends('layouts.app')

@section('content')
<div class="d-flex justify-content-end">
    <a href="" class="btn btn-success mb-2">Add Posts</a>
</div>

<div class="card card-default">
    <div class="card-header">Posts</div>

    <div class="card-body">
        <table class="table">
            <thead>
                <th>Image</th>
                <th>Title</th>
            </thead>
            <tbody>
                @foreach ($posts as $post)
                    <tr>
                        <td><img src=""></td>
                        <td></td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>
</div>
@endsection

.............

and this is the code of controller

public function store(CreatePostsRequest $request)
{
    //Upload the image

    $image = $request->image->store('public/img');
    //create the post
    Post::create([
        'title' => $request->title,
        'description' => $request->description,
        'content' => $request->content,
        'image' => $image
    ]);
    //flash a message with seasson

    session()->flash('success','Post created successfully');
    //redirect user

    return redirect(route('posts.index'));


}

and i linked the storage to the public folder. But still its not working



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire