/** * Get the most recent images in the DBs */ public function getRecentImages($amount, $selector) { $types = array('instagram', 'instatag'); # add 'facebook' to get the facebook images $fields = array('tid', 'user', 'content AS image', 'type'); $dbFields = array('tid', 'content AS image', 'type'); $images = Image::recentByTypes($types, $fields, $amount)->get(); $dbImages = Dbox::recent($dbFields, $amount)->get(); $dbImages->each(function ($item, $key) { if ($item->type == 'dropbox') { $item->image = "http://campingvlasmarkt.be/store/dropbox/" . $item->image; $item->user = "******"; } }); $images->each(function ($item, $key) { if ($item->type == 'instatag') { $item->type = "instagram"; } }); $merged = array_merge($images->toArray(), $dbImages->toArray()); shuffle($merged); return response()->json(['contents' => $merged, 'selector' => $selector]); }