App\Http\Controllers\CompaniesController Class Reference

This controller handles all actions related to Companies for the Snipe-IT Asset Management application. More...

Inheritance diagram for App\Http\Controllers\CompaniesController:
App\Http\Controllers\Controller

Public Member Functions

 getIndex ()
 Returns view to display listing of companies. More...
 
 getCreate ()
 Returns view to create a new company. More...
 
 postCreate ()
 Save data from new company form. More...
 
 getEdit ($companyId)
 Return form to edit existing company. More...
 
 postEdit ($companyId)
 Save data from edit company form. More...
 
 postDelete ($companyId)
 Delete company. More...
 

Detailed Description

This controller handles all actions related to Companies for the Snipe-IT Asset Management application.

Version
v1.0

Definition at line 17 of file CompaniesController.php.

Member Function Documentation

App\Http\Controllers\CompaniesController::getCreate ( )

Returns view to create a new company.

Author
[Abdullah Alansari] [ahimt.nosp@m.a@gm.nosp@m.ail.c.nosp@m.om]
Since
[v1.8]
Returns
View

Definition at line 39 of file CompaniesController.php.

40  {
41  return View::make('companies/edit')->with('company', new Company);
42  }
App\Http\Controllers\CompaniesController::getEdit (   $companyId)

Return form to edit existing company.

Author
[Abdullah Alansari] [ahimt.nosp@m.a@gm.nosp@m.ail.c.nosp@m.om]
Since
[v1.8]
Parameters
int$companyId
Returns
View

Definition at line 75 of file CompaniesController.php.

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  }
App\Http\Controllers\CompaniesController::getIndex ( )

Returns view to display listing of companies.

Author
[Abdullah Alansari] [ahimt.nosp@m.a@gm.nosp@m.ail.c.nosp@m.om]
Since
[v1.8]
Returns
View

Definition at line 27 of file CompaniesController.php.

28  {
29  return View::make('companies/index')->with('companies', Company::all());
30  }
App\Http\Controllers\CompaniesController::postCreate ( )

Save data from new company form.

Author
[Abdullah Alansari] [ahimt.nosp@m.a@gm.nosp@m.ail.c.nosp@m.om]
Since
[v1.8]
Returns
Redirect

Definition at line 51 of file CompaniesController.php.

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  }
App\Http\Controllers\CompaniesController::postDelete (   $companyId)

Delete company.

Author
[Abdullah Alansari] [ahimt.nosp@m.a@gm.nosp@m.ail.c.nosp@m.om]
Since
[v1.8]
Parameters
int$companyId
Returns
Redirect

Definition at line 121 of file CompaniesController.php.

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  }
App\Http\Controllers\CompaniesController::postEdit (   $companyId)

Save data from edit company form.

Author
[Abdullah Alansari] [ahimt.nosp@m.a@gm.nosp@m.ail.c.nosp@m.om]
Since
[v1.8]
Parameters
int$companyId
Returns
Redirect

Definition at line 93 of file CompaniesController.php.

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  }

The documentation for this class was generated from the following file: