/
DepartmentsController.php
60 lines (53 loc) · 1.41 KB
/
DepartmentsController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace App\Http\Controllers;
use Session;
use App\Http\Requests;
use App\Http\Requests\Department\StoreDepartmentRequest;
use App\Repositories\Department\DepartmentRepositoryContract;
class DepartmentsController extends Controller
{
protected $departments;
/**
* DepartmentsController constructor.
* @param DepartmentRepositoryContract $departments
*/
public function __construct(DepartmentRepositoryContract $departments)
{
$this->departments = $departments;
$this->middleware('user.is.admin', ['only' => ['create', 'destroy']]);
}
/**
* @return mixed
*/
public function index()
{
return view('departments.index')
->withDepartment($this->departments->getAllDepartments());
}
/**
* @return mixed
*/
public function create()
{
return view('departments.create');
}
/**
* @param StoreDepartmentRequest $request
* @return mixed
*/
public function store(StoreDepartmentRequest $request)
{
$this->departments->create($request);
Session::flash('flash_message', 'Successfully created New Department');
return redirect()->route('departments.index');
}
/**
* @param $id
* @return mixed
*/
public function destroy($id)
{
$this->departments->destroy($id);
return redirect()->route('departments.index');
}
}