/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(Request $request, $id) { $concerts = Concert::orderBy('created_at', 'asc')->get(); $currentConcert = Concert::where('id', $id)->first(); $artists = Artist::orderBy('created_at', 'asc')->get(); $lieux = array(); foreach ($concerts as $concert) { if (!in_array($concert->lieu, $lieux)) { $lieux[] = $concert->lieu; } } return view('admin_edit', ['lieux' => $lieux, 'artists' => $artists, 'currentConcert' => $currentConcert]); }
public function getPage(Request $request, $pageIndex) { $city = $request->input('city'); $tags = $request->input('tags'); $price = $request->input('price'); $matchThese = array(); if ($city != 'unspecified') { $matchThese['ville'] = $city; } if ($price != 'unspecified') { $matchThese['prix'] = $price; } $concertsQueryBuilder = Concert::orderBy('concerts.created_at', 'asc'); if ($tags != 'unspecified') { $matchThese['tags'] = $tags; $concertsQueryBuilder->join('artists', 'artists.id', '=', 'concerts.artist_id'); } $concertsQueryBuilder->where($matchThese); $concerts = $concertsQueryBuilder->get(); $villes = array(); $tags = array(); $prix = array(); foreach ($concerts as $concert) { if (!in_array($concert->ville, $villes)) { $villes[] = $concert->ville; } if (!in_array($concert->prix, $prix)) { $prix[] = $concert->prix; } if (!in_array($concert->artist->tags, $tags)) { $tags[] = $concert->artist->tags; } } $current_page = $pageIndex - 1; $concert_count = count($concerts); $page_count = $concert_count % SELF::CONCERTS_PER_PAGE != 0 ? floor($concert_count / SELF::CONCERTS_PER_PAGE) + 1 : floor($concert_count / SELF::CONCERTS_PER_PAGE); return view('concert_list', ['concerts' => $concerts, 'villes' => $villes, 'tags' => $tags, 'prix' => $prix, 'page_count' => $page_count, 'current_page' => $current_page]); }