pghs2kid's avatar

pulling all uploaded photos from database

Hello, I am new to all of this and this is my first website i have made (classified ads). I am using laravel 5.8 framework with a mysql database. I am trying to figure out how to upload all of my images to a view page.

Currently I have it setup to show only the first photo uploaded to the home page and category page, however, when you click on the page to view the whole ad i want to show all of the photos (think how ebay shows just one photo on the first page but then when you click the ad you can view more photos).

I think my problem lies in my use of strtok for pulling only one photo and then it stops at the ',' which is how my photos are uploaded from the user.

            <div class="col-md-12">
            <div class="productCard">
	<img style=" width:100%;height:100%; " src=<?php echo strtok($row->photos, ',')?> />
	<h3 style="margin-bottom: 0px; font-size: medium; font-weight: bold;">${{$row->price}}</h3>
	<h3 style="margin-bottom: 0px; font-size: small; font-weight: bold;">{{$row->year}} {{$row->make}} {{$row->model}}</h3>
           <h3 style="margin-bottom: 0px; font-size: small;">{{$row->city}} {{$row->state}}</h3>
        <h3 style="margin-bottom: 20px; margin-top: 20px; font-size: large;">{{$row->description}}</h3>

here is my controller. I think what i want to do is instead of using strtok use implode if possible? I just dont know how to write that in my blade file?

                 $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->maincategoryid = $request->input('maincategoryid');
        $ads->subcategoryid = $request->input('subcategoryid');
        $ads->description = $request->input('description');
        $ads->year = $request->input('year');
        $ads->make = $request->input('make');
        $ads->model = $request->input('model');
        $ads->price = $request->input('price');
        $ads->email = $request->input('email');
        $ads->state = $request->input('state');
        $ads->city = $request->input('city');
        $ads->photos = $image;
        $ads->save();
        return redirect('/')->with('info', 'Listing published successfully');
0 likes
11 replies
Sergiu17's avatar

Hi, iterate over them and print every individual image

@foreach( $row->photos as $photo )
	<img src="{{ $photo->name }}" /> 
@endforeach
1 like
jlrdw's avatar

You should paginate the photos. Imagine trying to load too many on a mobile device.

1 like
pghs2kid's avatar

the images come from the individual posting if that makes sense? so i wouldn't know what the image names are until someone posts them. would this method still work for that?

pghs2kid's avatar

how do I paginate the photos? this would help since its already pretty slow on mobile

jlrdw's avatar

That's where you setup authentication and authorization and show the images via a authorized user id.

Have you viewed some of Jeffries free from scratch videos.

2 likes
jlrdw's avatar

See pagination in the documentation.

2 likes
pghs2kid's avatar

Now i see what youre saying, but let me rephrase. The page I am trying to load all of the photos to are only the photos connected to that unique user. picture ebay how it only shows one image but then when you click that listing it shows all of the other photos connected to that listing. This page will be limited to 6 photos. However, that will be extremely useful for the home page, thanks!

pghs2kid's avatar

if i just print it within a heading tag like this

{{$row->photos}}

it does show the text of all 3 photos in relation to the listings id but doesnt show the images since its not a img tag however in a img tag written just like that it shows no images.

pghs2kid's avatar

the question has been updated to hopefully better illustrate what i am trying to do. thanks for the replies

jlrdw's avatar

Step one would be just try and experimenting some with various layouts and some trial and error.

Please or to participate in this conversation.