Reputation: 25
I want to create a site that provides images outside.
But, I want to show a random image even if the image uses the same url.
For example, if I use http://www.example.com/test.jpg">, I want to show test1.jpg or test2.jpg on my server at random (or on other conditions).
Is this possible? I know that browser users pre-store the cache in a temporary folder and recycle it. But Is there any way?
Alternatively, is it possible to have the various images randomly displayed by typing http://www.example.com/test?
Thanks your advice in advance.
Upvotes: 0
Views: 690
Reputation: 1795
In routes\web.php just make a Get route like this:
Route::get('test.jpg',function(){
$images=['test1.jpg','test2.jpg','test3.jpg'];
$randimage=shuffle($images);
return '<image src="images/'.$images[0].'">';
});
the shuffle function change the ordering of items so that in every request you'll see a new image in that route
(it's just an example,better to use a controller and code in there bro)
hope be helpfull
Upvotes: 2