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);
}
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.