public function anyImage(Request $r) { // Запрос конкретной картинки $img_id = $r->get('img', false); if ($img_id !== false) { // выбираем картинку $img = WallpaperImage::where('category', $img_id)->first(); return resp($img); } // получаем id категории $cat = $r->get('cat', false); $category = intval($cat === false ? rand(1, WallpaperCategoty::max('id')) : $cat); // выбираем картинку $img = WallpaperImage::where('category', $category)->orderByRaw("RAND()")->first(); return resp($img); }
/** * Run the database seeds. * * @return void */ public function run() { WallpaperCategoty::truncate(); WallpaperCategoty::create(['name' => 'Аниме', 'description' => 'Персонажи аниме и сопутствующей тематики', 'preview' => 'http://anime.anime-skorpik.com/uploads/posts/2013-12/1386612195_gjedbxz8clc.jpg']); WallpaperCategoty::create(['name' => 'Абстракция', 'description' => 'Необычные виды', 'preview' => 'http://file.mobilmusic.ru/14/d9/1c/697645.jpg']); }