Esempio n. 1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id = null)
 {
     // If multiple ids are specified
     if ($id == 'multiple') {
         $selected_ids = trim(Input::get('selected_ids'));
         if ($selected_ids == '') {
             return Redirect::back()->with('error_message', "Nothing was selected to delete");
         }
         $selected_ids = explode(' ', $selected_ids);
     } else {
         $selected_ids = array($id);
     }
     $company_model = $this->module_namespace . "Models\\Company";
     foreach ($selected_ids as $id) {
         if (can_user_access_company($id)) {
             $company = $company_model::findOrFail($id);
             $company->delete();
         }
     }
     if (count($selected_ids) > 1) {
         $message = 'The companies were deleted';
     } else {
         $message = 'The company was deleted';
     }
     return Redirect::back()->with('success_message', $message);
 }
Esempio n. 2
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @param $form_id
  */
 public function edit($id)
 {
     if ($this->module_vendor) {
         $company_branch_model = "Modules\\{$this->module_vendor}\\{$this->module_alias}\\Models\\CompanyBranch";
     } else {
         $company_branch_model = "Modules\\{$this->module_alias}\\Models\\CompanyBranch";
     }
     $country_model = $this->module_namespace . 'Models\\Country';
     $company_model = $this->module_namespace . 'Models\\Company';
     $countries = $country_model::names();
     $companies = $company_model::names();
     $company_branch = $company_branch_model::with('incharges')->findOrFail($id);
     if (!can_user_access_company($company_branch->company_id)) {
         abort(501);
     }
     $incharge_count = $company_branch->incharges->count() ?: 1;
     $this->layout->title = "Edit Entry in {$this->module_name}";
     $this->layout->content = View::make("{$this->module_alias}::branches.{$this->type}.create_edit")->with('title', "Edit Entry in module {$this->module_name}")->with('company_branch', $company_branch)->with('countries', $countries)->with('companies', $companies)->with('incharge_count', $incharge_count);
 }