/** * 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'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, tenantRequest $request) { $tenant = Tenant::findOrFail($id); $tenant->update($request->all()); return Redirect::route('tenants.index'); }