Home > Enterprise >  I upload a post and the image is not being visualized
I upload a post and the image is not being visualized

Time:07-16

Im uploading posts that are images and they are being stored in my storage folder but they are not being visualized in my browser. It appears as if there is a post but the image is not being showed.

I already have a storage:link.

This is my store function in my PostsController:

public function store (Request $req) {
        $rules = [
    "image" => "required|image",
    "description" => "string",
    "user_id" => "integer"

];

$this->validate($req, $rules);



$post = New Post();

$post->image = $req->file('image')->store('/');

        $post->description = $req->description;
        $post->user_id = $req->user()->id;




        $post->save();


        return redirect("/post/" . $post->id);
    }

enter image description here

CodePudding user response:

public function store (Request $req) {

$rules = [
    "image" => "required|image",
    "description" => "string",
    "user_id" => "integer"

];

$this->validate($req, $rules);


$image = $req->file('image')
$name = $image->getClientOriginalName();
$image->move(public_path().'/uploads/', $name);

$post = New Post();
$post->description = $req->description;
$post->user_id = $req->user()->id;
$post->image = $name;
$post->save();

return redirect("/post/" . $post->id);

}

CodePudding user response:

check the file paths correctness and try with different browser such as chrome. also check is there a image in storage file.

  • Related