|
46 | 46 |
|
47 | 47 | require(app_path(). '/functions.php'); |
48 | 48 |
|
49 | | - $cache_key = 'photos-cache-key'; |
| 49 | + $cache_key = 'photos-cache-key2'; |
50 | 50 | $faker = \Faker\Factory::create(); |
51 | 51 |
|
52 | 52 | if(\Cache::has($cache_key)) |
53 | 53 | $photos = cache($cache_key); |
54 | 54 | else{ |
55 | 55 | $photos = json_decode(file_get_contents("https://picsum.photos/v2/list")); |
56 | | - cache([$cache_key => $photos], 60); |
| 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 | +
|
| 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 | + } |
| 68 | +
|
| 69 | + cache([$cache_key => $photos_with_desc], 60); |
57 | 70 | } |
58 | 71 |
|
59 | 72 | @endphp |
|
65 | 78 | <div class="card mb-4 shadow-sm"> |
66 | 79 | <img src="https://picsum.photos/id/{{$photo->id}}/348/225"/> |
67 | 80 | <div class="card-body"> |
68 | | - <p class="card-text">{{ $faker->realText }}</p> |
| 81 | + <p class="card-text">{{ $photo->Description }}</p> |
69 | 82 | <div class="d-flex justify-content-between align-items-center"> |
70 | 83 | <div class="btn-group"> |
71 | 84 | <button type="button" class="btn btn-sm btn-outline-secondary"> |
72 | | - <span class="oi oi-arrow-thick-top"></span> |
| 85 | + <a href="/track.php?vote_method=up&photoID={{$photo->id}}"><span class="oi oi-arrow-thick-top"></span></a> |
73 | 86 | </button> |
74 | 87 | <button type="button" class="btn btn-sm btn-outline-secondary"> |
75 | | - <span class="oi oi-arrow-thick-bottom"></span> |
| 88 | + <a href="/track.php?vote_method=down&photoID={{$photo->id}}"><span class="oi oi-arrow-thick-bottom"></span></a> |
76 | 89 | </button> |
77 | 90 | </div> |
78 | | - <small class="text-muted">{{ mt_rand(100,10000)}} votes</small> |
| 91 | + <small class="text-muted">{{ $photo->Votes}} votes</small> |
79 | 92 | </div> |
80 | 93 | </div> |
81 | 94 | </div> |
|
0 commit comments