/** * Display a listing of the resource. * * @return Response */ public function index() { $posts = Post::orderBy('created_at', 'desc')->take(5)->get(); $reservations = Reservation::where('valide', '<', 2)->get(); $velos = Velo::all(); return view('admin.dashboard')->with(['posts' => $posts, 'reservations' => $reservations, 'velos' => $velos]); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); User::create(['name' => 'Yohann', 'email' => '*****@*****.**', 'role' => 'admin', 'password' => bcrypt('admin'), 'phone' => '0125654520']); Post::create(['titre' => 'Exemple actu', 'contenu' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sit amet congue nisi, eu egestas velit. Donec tincidunt nisi nec efficitur pretium. Aliquam arcu nisi, tristique in ex eget, ultricies accumsan erat. Aliquam erat volutpat. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus vitae massa ligula. Aenean fermentum tellus ut dapibus scelerisque. Morbi vel finibus nisl. Integer feugiat dui nisl. Morbi sit amet massa eu libero lacinia volutpat ac in nisi. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent facilisis magna eu ante venenatis commodo. Fusce auctor elit venenatis ipsum finibus viverra. Sed imperdiet molestie dui, eget dignissim massa gravida sit amet. In maximus est lectus, vitae consequat nibh imperdiet in. Maecenas maximus id dui sit amet hendrerit. Morbi a tellus vel magna ultricies egestas id ut mi. Duis sed dolor sit amet ipsum ullamcorper laoreet in id purus. Fusce vehicula orci et venenatis tristique. Morbi nec cursus erat. Ut suscipit molestie nisi maximus cursus. Praesent quis luctus est. Nullam finibus metus dolor, a posuere est pretium id. Nullam ornare in purus sed efficitur. Vivamus id ipsum ut dui blandit dictum. Aenean ante elit, condimentum non libero vitae, blandit efficitur eros. Nullam rutrum tortor non orci congue, id auctor lacus hendrerit. Phasellus fringilla sem placerat erat mollis mollis ut rhoncus nunc. Etiam ornare pretium tempus. Nunc felis metus, viverra eget hendrerit et, blandit nec purus. Aliquam ut lectus non nibh sodales mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris congue pellentesque nunc, in volutpat leo mattis sit amet. Etiam porta, turpis eu pharetra scelerisque, tortor tortor iaculis nisl, a fermentum sem felis vitae est. Pellentesque tristique, ex a fringilla sollicitudin, mi tellus gravida orci, vitae scelerisque nisi leo eu lectus.', 'chapo' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sit amet congue nisi, eu egestas velit. Donec tincidunt nisi nec efficitur pretium. Aliquam arcu nisi, tristique in ex eget, ultricies accumsan erat. Aliquam erat volutpat.', 'slug' => 'exemple-actu']); Reservation::create(['user_id' => 1, 'velo_id' => 1, 'valide' => false]); Reservation::create(['user_id' => 1, 'velo_id' => 2, 'valide' => false]); Demijournee::create(['date' => '2010-05-02', 'periode' => 'am', 'reservation_id' => 1]); Demijournee::create(['date' => '2011-07-01', 'periode' => 'pm', 'reservation_id' => 2]); Velo::create(['modele' => 'Vélo de la mort', 'categorie' => 'enfant', 'image' => '']); Velo::create(['modele' => 'Véloette', 'categorie' => 'adulte', 'image' => '']); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $nbRes = Reservation::where('user_id', '=', Auth::user()->id)->where('valide', '<=', 1)->count(); if ($nbRes < 3) { $velo = Velo::findOrFail($request->input('idVelo')); // Création d'une nouvelle reservation $reservation = new Reservation(['valide' => 0]); $reservation->user()->associate(Auth::user()); $reservation->velo()->associate($velo); $reservation->save(); // Création des demi journéées choisies $values = $request->all(); $keys = array_keys($values); $newDJ = array(); unset($keys[0]); //on retire le token for ($i = 1; $i < sizeof($values) - 2; $i += 2) { // -2 pour retirer le veloId //control des champs $regles = array($keys[$i] => 'required', $keys[$i + 1] => 'required'); $validation = Validator::make($values, $regles); if ($validation->fails()) { Session::flash('info', 'Le formulaire envoyé comportait des champs vides !'); $reservation->delete(); foreach ($newDJ as $dj) { $dj->delete(); } return redirect()->back(); } else { //formattage de la date $date = explode('-', $values[$keys[$i]]); $date = $date[2] . '-' . $date[1] . '-' . $date[0]; $demijournee = new Demijournee(['date' => $date, 'periode' => $values[$keys[$i + 1]]]); $demijournee->reservation()->associate($reservation); $demijournee->save(); $newDJ[] = $demijournee; } } return redirect()->route('location.show', ['location' => $reservation->id]); } else { Session::flash('info', 'Vous ne pouvez pas avoir plus de trois réservations en attente ! Merci de votre compréhension.'); return redirect()->back(); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $velo = Velo::findOrFail($id); if (file_exists($velo->image)) { unlink($velo->image); } $velo->delete(); Session::flash('info', "L'élément a bien été supprimé"); return redirect('/admin/dashboard'); }