示例#1
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]);
 }
示例#2
0
 /**
  * Function Store
  * to Save/Update Brand From Brand Form
  * @Request @Name,@Code etc
  *
  * @return json
  */
 public function onStore(\App\Http\Requests\CompanyRequest $request)
 {
     $is_exist = \App\Models\Company::where('name', $request->get('name'))->where('id', '!=', $request->get('id'))->get(['id'])->first();
     if ($is_exist) {
         $param['error'] = true;
         $param['message'] = Lang::get('message.companies unique name');
         return json_encode($param);
     }
     $companies = new \App\Models\Company();
     if ($request->has('id')) {
         $companies = $companies->where('id', $request->get('id'))->first();
         $companies->updated_at = date('Y-m-d H:i:s');
         $companies->updated_by = Auth::user()->id;
     } else {
         $companies->created_at = date('Y-m-d H:i:s');
         $companies->created_by = Auth::user()->id;
     }
     $companies->_id = $request->get('company_id');
     $companies->name = $request->get('name');
     $companies->active = $request->get('active') ? $request->get('active') : 0;
     $companies->save();
     $param['id'] = $companies->id;
     $param['message'] = $request->get('id') ? Lang::get('info.updated') : Lang::get('info.inserted');
     $param['error'] = false;
     return json_encode($param);
 }