public function insertBorrower($id)
 {
     $borrower_id = Auth::user()->student_id;
     $contract = Contract::where('contract_id', $id)->first();
     $contract->borrower_id = $borrower_id;
     $contract->save();
     $student = Student::where('student_id', $borrower_id)->first();
     $data = array('email' => $student->email, 'first_name' => $student->first_name);
     Mail::send('emails.success', $data, function ($message) use($data) {
         $message->from('*****@*****.**', 'ShareBook');
         $message->to($data['email']);
         $message->subject('Successfully Borrowed Textbook!');
     });
     $due_date = new DateTime($contract->due_date);
     $reminder_date = $due_date->modify('-1 Week');
     $today = new DateTime("now");
     $interval = $reminder_date->getTimestamp() - $today->getTimestamp();
     Mail::later($interval, 'emails.reminder', $data, function ($message) use($data) {
         $message->from('*****@*****.**', 'ShareBook');
         $message->to($data['email']);
         $message->subject('Due Date Reminder');
     });
     $book = Book::where('book_id', $contract->book_id);
     $book->delete();
     \Session::flash('message', 'Successfully borrowed textbook!');
     return view('index');
 }
 /**
  * Store a newly created book in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     // validate
     // read more on validation at http://laravel.com/docs/validation
     $rules = array('name' => 'required', 'author' => 'required', 'isbn' => 'required', 'publisher' => 'required', 'edition' => 'required|numeric', 'faculty' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // // process the share redirect
     if ($validator->fails()) {
         \Log::error($request, $rules);
         return Redirect::to('share')->withErrors($validator);
     } else {
         // store book
         $book = Book::firstOrCreate(['name' => Input::get('name'), 'author' => Input::get('author'), 'isbn' => Input::get('isbn'), 'publisher' => Input::get('publisher'), 'edition' => Input::get('edition'), 'faculty' => Input::get('faculty')]);
         $book->save();
         $user = Auth::user();
         $book->student_id = $user->student_id;
         $book->save();
         // USE THIS WHEN BORROW BUTTON CLICKED
         // $contract = Book::find(1)->contracts()->where('book_id', '=', $book->book_id);
         $pickup_date = strtotime(Input::get('pickup_date'));
         $due_date = strtotime(Input::get('due_date'));
         \Log::info($pickup_date);
         $contract = new Contract();
         $contract->sharer_id = $user->student_id;
         $contract->book_id = $book->book_id;
         $contract->pickup_date = date('Y-m-d H:i:s', $pickup_date);
         $contract->location = Input::get('location');
         $contract->due_date = date('Y-m-d H:i:s', $due_date);
         $contract->save();
         $image = Input::file('image');
         $extension = $image->getClientOriginalExtension();
         $book_id = $book->book_id;
         $filename = $book_id . '.' . $extension;
         $path = public_path('uploads/' . $filename);
         \Image::make($image->getRealPath())->resize(50, 67)->save($path);
         $book->image = 'uploads/' . $filename;
         $book->image = $filename;
         $book->save();
         \Session::flash('message', 'Successfully created book!');
         // redirect
         return Redirect::to('index');
     }
 }