I am trying to show all my photos from my database in relation to the user id where they are stored. If i do something like this it obviously works to display the text in an array however i need to know how to replace that text with my images.
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str));
Here is how I am storing the photos. they are stored in my uploads folder of the project as well as in the database under $row->photos
if i print <h3>$row->photos<h3>
to my site it will bring up all of the photos that i wish to show, so i do know they are there.
this is how im storing them and you can see where they are moved to my uploads folder.
$ads = new Listings;
$images = $request->file('photos');
$count = 0;
if($request->file('photos')){
foreach($images as $item){
if($count < 6){
$var = date_create();
$date = date_format($var, 'Ymd');
$imageName = $date.'_'.$item->getClientOriginalName();
$item->move(public_path().'/uploads/',$imageName);
$url = URL::to("/").'/uploads/'.$imageName;
$arr[] = $url;
$count++;
}
}
$image = implode(",", $arr);
$ads->photos = $image;
return redirect('/')->with('info', 'Listing published successfully');
here is the code used for the view I want to put the photos in
public function view(Request $request, $id){
$ads = DB::table('listings')
->select ('listings.id', 'photos', 'description', 'year', 'make', 'model', 'price', 'city', 'state', 'email')
->where(['id' => $id])
->get();
$output = '';
if($ads->count() > 0){
return view('users.posted.postedads', ['id'=>$id, 'ads'=>$ads]);
}
}
}
This worked perfectly
@foreach
(explode(',', $row->photos) as $row->photos)
<img src="{{$row->photos}}" style="width:75%; height:75%; align-content: center;">
@endforeach