Ejemplo n.º 1
0
 public function show($id)
 {
     $equipments = Equipment::findOrFail($id)->first();
     return view('equipments.show', compact('equipments'));
 }
Ejemplo n.º 2
0
 /**
  * @param int $id The equipment you want to check out on
  * @return \Illuminate\Http\RedirectResponse|string
  */
 public function checkout($id)
 {
     // FindOrFail because we don't want anyone checking out on nonexistant equipment
     $equipment = Equipment::findOrFail($id);
     $user = \Auth::id();
     // Get today's range
     $now = new Carbon('now');
     $start = clone $now->hour(0)->minute(0)->second(0);
     $end = clone $now->hour(23)->minute(59)->second(59);
     // Not checked out, checked in, and checkin was today
     $checkin = Checkin::where('user_id', $user)->where('equipment_id', $id)->whereNotNull('checkin')->whereNull('checkout')->whereBetween('checkin', [$start, $end])->first();
     // No checkin? No dice.
     if ($checkin === null) {
         return "Error: You're not checked in.";
     }
     // All is well, write checkout to database
     $checkin->update(['checkout' => new \DateTime()]);
     return redirect()->back();
     // "You have been checked out";
 }
Ejemplo n.º 3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Equipment $equipment)
 {
     try {
         $equipment = Equipment::findOrFail(Input::get('id'));
     } catch (Exception $e) {
         return Redirect::to('/admin.equipment.index')->with('flash_message', 'equipment not found');
     }
     $equipment->name = Input::get('name');
     $equipment->save();
     return Redirect::action('EquipmentController@index')->with('flash_message', 'Your Equipment has been saved.');
 }