/**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, contractRequest $request)
 {
     // use my custom handler to fix dates, check if dates are valid and see if the stores are available to rent
     $contractFormHandler = new ContractFormHandler($request);
     if ($contractFormHandler->hasErrors) {
         \Session::flash('message', $contractFormHandler->errorMessages);
         \Session::flash('messageType', 'warning');
         return redirect()->route('contracts.edit', ['contracts' => $id])->withInput();
     }
     // remove previous associations to replace with new form
     $contract = Contract::findOrFail($id);
     $contract->tenant()->dissociate();
     $contract->properties()->detach();
     // update info
     $contract->description = $request->description;
     $contract->effective_date = $request->effective_date;
     $contract->expiry_date = $request->expiry_date;
     $contract->terms = $request->terms;
     $contract->signing_date = $request->signing_date;
     $contract->amount = $request->amount;
     $contract->currency = $request->currency;
     // associate with tenant
     $tenant = Tenant::findOrFail($request->tenant);
     $contract->tenant()->associate($tenant);
     // attach properties
     foreach ($request->properties as $key => $property) {
         $propertyInFocus = Property::findOrFail($property);
         $contract->properties()->attach($propertyInFocus);
     }
     $contract->save();
     return redirect()->route('contracts.index');
 }
 public function update($id, ContractRequest $request)
 {
     $contract = Contract::findOrFail($id);
     $contract->update($request->all());
     return redirect('contracts');
 }
 public function ContractRevenueDetail($id)
 {
     $contract = Contract::findOrFail($id);
     $revenues = $contract->revenues->groupBy('weekPaidOn');
     $revenues->transform(function ($item, $key) {
         return $item->transform(function ($item, $key) {
             return ['week' => $item->weekPaidOn, 'date' => $item->created_at->toFormattedDateString(), 'amount' => $item->amount_paid];
         });
     });
     return $revenues;
 }