Search Results

Go to the documentation of this file.
1 <?php
2 namespace App\Http\Controllers;
3 
5 use Input;
6 use Lang;
7 use Redirect;
8 use View;
9 
17 final class CompaniesController extends Controller
18 {
19 
27  public function getIndex()
28  {
29  return View::make('companies/index')->with('companies', Company::all());
30  }
31 
39  public function getCreate()
40  {
41  return View::make('companies/edit')->with('company', new Company);
42  }
43 
51  public function postCreate()
52  {
53  $company = new Company;
54 
55  $company->name = e(Input::get('name'));
56 
57  if ($company->save()) {
58  return Redirect::to('admin/settings/companies')
59  ->with('success', trans('admin/companies/message.create.success'));
60  } else {
61  return Redirect::back()->withInput()->withErrors($company->getErrors());
62  }
63 
64  }
65 
66 
75  public function getEdit($companyId)
76  {
77  if (is_null($company = Company::find($companyId))) {
78  return Redirect::to('admin/settings/companies')
79  ->with('error', trans('admin/companies/message.does_not_exist'));
80  } else {
81  return View::make('companies/edit')->with('company', $company);
82  }
83  }
84 
93  public function postEdit($companyId)
94  {
95  if (is_null($company = Company::find($companyId))) {
96  return Redirect::to('admin/settings/companies')->with('error', trans('admin/companies/message.does_not_exist'));
97  } else {
98 
99 
100  $company->name = e(Input::get('name'));
101 
102  if ($company->save()) {
103  return Redirect::to('admin/settings/companies')
104  ->with('success', trans('admin/companies/message.update.success'));
105  } else {
106  return Redirect::to("admin/settings/companies/$companyId/edit")
107  ->with('error', trans('admin/companies/message.update.error'));
108  }
109 
110  }
111  }
112 
121  public function postDelete($companyId)
122  {
123  if (is_null($company = Company::find($companyId))) {
124  return Redirect::to('admin/settings/companies')
125  ->with('error', trans('admin/companies/message.not_found'));
126  } else {
127  try {
128  $company->delete();
129  return Redirect::to('admin/settings/companies')
130  ->with('success', trans('admin/companies/message.delete.success'));
131  } catch (\Illuminate\Database\QueryException $exception) {
132  /*
133  * NOTE: This happens when there's a foreign key constraint violation
134  * For example when rows in other tables are referencing this company
135  */
136  if ($exception->getCode() == 23000) {
137  return Redirect::to('admin/settings/companies')
138  ->with('error', trans('admin/companies/message.assoc_users'));
139  } else {
140  throw $exception;
141  }
142  }
143  }
144  }
145 }
getIndex()
Returns view to display listing of companies.
Model for Companies.
Definition: Company.php:12
This controller handles all actions related to Companies for the Snipe-IT Asset Management applicatio...
getEdit($companyId)
Return form to edit existing company.
postCreate()
Save data from new company form.
postEdit($companyId)
Save data from edit company form.
getCreate()
Returns view to create a new company.