configjeu()->where('actifMemo', '=', '1')->first(); if($configjeu && count($configjeu->oeuvres) >= 1) { $oes = $configjeu->oeuvres; $params = json_decode($configjeu->parametres); $bloc = $params->{"m".$niveau}; $nbParie = $params->{"mt"}; } else { $nbParie = 1; $oes = Oeuvre::orderByRaw("RAND()")->take(8)->get(); if($niveau == 1) {$bloc = 2;} elseif($niveau == 2){$bloc = 3;} else {$bloc = 4;} } return view('frontend/memo', ['oeuvres' => $oes, 'niveau' => $niveau, 'nbBloc'=>$bloc, 'nbPartie'=> $nbParie]); } public function playPuzzle($niveau) { try { $idRef = Cookie::get('referent'); $ref = Referent::findOrFail($idRef); $configjeu = $ref->configjeu()->where('actifPuzzle', '=', '1')->firstOrFail(); if(count($configjeu->oeuvres->count()) >= 1) { $oes = $configjeu->oeuvres()->select('image')->get(); $params = json_decode($configjeu->parametres); $nbTab = $params->pt; $dimension = $params->{"p" . $niveau}; if(!(isset($dimension) && is_numeric($dimension))) throw new ModelNotFoundException(); } else throw new ModelNotFoundException(); } catch(ModelNotFoundException $e) { $oes = Oeuvre::orderByRaw("RAND()")->take(5)->select('image')->get(); $nbTab = 3; $dimension = 2; } return view('frontend/puzzle', ['oeuvres' => $oes, 'dimension' => $dimension, 'nbTab' => $nbTab, 'niveau' => $niveau]); } public function index() { $res = User::referents()->get(); return view('home', ['referent' => $res]); } public function setRecords($idTrophee) { $cookie = Cookie::get('trophee'); $values = json_decode($cookie); if (!is_array($values)) $values = [0, 0, 0]; switch ($idTrophee) { case '1': $values[0] += 1; break; case '2': $values[1] += 1; break; case '3': $values[2] += 1; break; default: break; } return Response::make('all good!')->withCookie(Cookie::forever('trophee', json_encode($values))); } }