/** * Fetches a random element, from a specific category if supplied. * * @param null $ofCategory * @return mixed */ public static function getRandomElement($ofCategory = null) { $elements = null; if (!is_null($ofCategory)) { $types = ElementType::whereCategory($ofCategory)->get(['type'])->lists('type'); $elements = Element::whereIn('type', $types)->get(); } else { $elements = Element::all(); } if ($elements->count() > 0) { return $elements->random(); } }
private function randomId() { return Element::all(['id'])->random()['id']; }
public function index() { $elements = Element::all(['name', 'description', 'image', 'type']); $types = ElementType::all(); return view('wardrobe.index', compact('elements', 'types')); }