|
52 | 52 | if(\Cache::has($cache_key)) |
53 | 53 | $photos = cache($cache_key); |
54 | 54 | else{ |
55 | | - $photos = json_decode(file_get_contents("https://picsum.photos/v2/list")); |
56 | | - $photos_with_desc = array_map(function($item) use($faker){ |
57 | | - $item->Description = $faker->realText; |
58 | | - $item->Votes = 0; |
59 | | - return $item; |
60 | | - }, $photos); |
61 | 55 |
|
62 | | - foreach($photos_with_desc as $photo){ |
63 | | - $exists = checkIFPhotoExists($photo->id); |
64 | | - if(!$exists){ |
65 | | - InsertINTODB($photo->id, $photo->width, $photo->height,$photo->author,$photo->Description); |
66 | | - } |
67 | | - } |
| 56 | + $photos = \App\Entries::all(); |
| 57 | + if(count($photos)<=0){ |
| 58 | + $photos_from_api = json_decode(file_get_contents("https://picsum.photos/v2/list")); |
| 59 | +
|
| 60 | + $photos_with_desc = array_map(function($item) use($faker){ |
| 61 | + $item->Description = $faker->realText; |
| 62 | + $item->Votes = 0; |
| 63 | + $item->photoid = $item->id; |
| 64 | + return $item; |
| 65 | + }, $photos_from_api); |
68 | 66 |
|
69 | | - cache([$cache_key => $photos_with_desc], 60); |
| 67 | + foreach($photos_with_desc as $photo){ |
| 68 | + $exists = checkIFPhotoExists($photo->id); |
| 69 | + if(!$exists){ |
| 70 | + InsertINTODB($photo->id, $photo->width, $photo->height,$photo->author,$photo->Description); |
| 71 | + } |
| 72 | + } |
| 73 | + $photos = $photos_with_desc; |
| 74 | + cache([$cache_key => $photos], 60); |
| 75 | + } |
70 | 76 | } |
71 | 77 |
|
72 | 78 | @endphp |
|
76 | 82 | @foreach($photos as $photo) |
77 | 83 | <div class="col-md-4"> |
78 | 84 | <div class="card mb-4 shadow-sm"> |
79 | | - <img src="https://picsum.photos/id/{{$photo->id}}/348/225"/> |
| 85 | + <img src="https://picsum.photos/id/{{$photo->photoid}}/348/225"/> |
80 | 86 | <div class="card-body"> |
81 | 87 | <p class="card-text">{{ $photo->Description }}</p> |
82 | 88 | <div class="d-flex justify-content-between align-items-center"> |
83 | 89 | <div class="btn-group"> |
84 | 90 | <button type="button" class="btn btn-sm btn-outline-secondary"> |
85 | | - <a href="/track.php?vote_method=up&photoID={{$photo->id}}"><span class="oi oi-arrow-thick-top"></span></a> |
| 91 | + <a href="/track.php?vote_method=up&photoID={{$photo->photoid}}"><span class="oi oi-arrow-thick-top"></span></a> |
86 | 92 | </button> |
87 | 93 | <button type="button" class="btn btn-sm btn-outline-secondary"> |
88 | | - <a href="/track.php?vote_method=down&photoID={{$photo->id}}"><span class="oi oi-arrow-thick-bottom"></span></a> |
| 94 | + <a href="/track.php?vote_method=down&photoID={{$photo->photoid}}"><span class="oi oi-arrow-thick-bottom"></span></a> |
89 | 95 | </button> |
90 | 96 | </div> |
91 | 97 | <small class="text-muted">{{ $photo->Votes}} votes</small> |
|
0 commit comments