/**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(\App\Http\Requests\CompanyRequest $request, $id)
 {
     # try
     # {
     #    \DB::beginTransaction();
     $company = $this->companies->find($id);
     $this->companies->update($request->except(['phone', 'email', 'address', '_token', '_method']), $company->id);
     $this->companies->updateEmails($request->get('email'), $company->id);
     $this->companies->updatePhones($request->get('phone'), $company->id);
     $this->companies->updateAddress($request->get('address'), $company->id);
     #    	\DB::commit();
     #  }
     # catch(Exception $e)
     # {
     #    \DB::rollback();
     #   \Session::flash('delete_message', 'Something went wrong.');
     #   return redirect ('companies.edit', $company->id);
     #}
     \Session::flash('update_message', 'Company has been updated');
     return redirect('companies');
 }
Beispiel #2
0
 /**
  * Update the specified resource in storage.
  *
  * @return \Illuminate\Http\Response
  */
 public function update(CompanyRequest $request, $slug)
 {
     $company = Company::where(compact('slug'))->firstOrFail();
     // Check authorisation and throw 404 if not
     if (!Auth::user()->allowedTo('edit', 'company', $company)) {
         return view('errors/404');
     }
     $company_request = $request->except('supervisors', 'trades', 'tabs');
     // If not Transient set field to 0 and clear supervisors
     if (!$request->has('transient')) {
         $company_request['transient'] = '0';
     }
     // Empty State field if rest of address fields are empty
     //if (!$company_request['address'] && !$company_request['suburb'] && !$company_request['postcode'])
     //    $company_request['state'] = '';
     $company->update($company_request);
     // Update trades + supervisors for company
     // Only updatable by 'parent' company
     if ($company->parentCompany->id == Auth::user()->company->id) {
         if ($request->get('trades')) {
             $company->tradesSkilledIn()->sync($request->get('trades'));
         } else {
             $company->tradesSkilledIn()->detach();
         }
         if ($request->has('transient')) {
             $company->supervisedBy()->sync($request->get('supervisors'));
         } else {
             $company->supervisedBy()->detach();
         }
     }
     // Actions for making company inactive
     // delete company from future planner
     // delete future leave
     // make company users inactive
     Toastr::success("Saved changes");
     $tabs = explode(':', $request->get('tabs'));
     return redirect('/company/' . $company->slug . '/' . $tabs[0] . '/' . $tabs[1]);
 }