Reputation: 135
I am uploading images on laravel 9.it is uploading successfully.but when view the images couldn't shown up.i don't know why is this problem. when upload the image and save it shown up the link on the database table link. look like this /storage/images/1671456399_car1.jpg
i check through console http://127.0.0.1:8000/ url displayed look like this
here where i view the images
<td>
<img src="{{ asset($item->photo) }}" width= '50' height='50' class="img img-responsive" />
</td>
Save the images code
$requestData = $request->all();
$filename = time()."_".$request->file('photo')->getClientOriginalName();
$path = $request->file('photo')->storeAs('images',$filename,'public');
$requestData["photo"] = '/storage/'.$path;
Teacher::create($requestData);
this is value of $item-photo
<img src="http://127.0.0.1:8000/" width="50" height="50" class="img img-responsive">
Upvotes: 0
Views: 171
Reputation: 2165
The problem is in image store path. Replace the code of store image and you will get a image.
$requestData = $request->all();
$filename = time()."_".$request->file('photo')->getClientOriginalName();
$path = $request->file('photo')->move(public_path('/images'),$filename);
$requestData["photo"] = '/images/'.$filename;
Teacher::create($requestData);
Upvotes: 0