source: app/Http/Controllers/Dashboard/DepartmentsController.php@ 194a359

develop
Last change on this file since 194a359 was 194a359, checked in by beratkjufliju <kufliju@…>, 3 years ago

added departments, edited users and added user settings

  • Property mode set to 100644
File size: 1.8 KB
Line 
1<?php
2
3namespace App\Http\Controllers\Dashboard;
4
5use App\Helpers\Alert;
6use App\Http\Requests\Dashboard\NewDepartmentRequest;
7use App\Http\Requests\Dashboard\UpdateDepartmentRequest;
8use App\Models\Department;
9use App\Models\User;
10use Illuminate\Http\Request;
11use App\Http\Controllers\Controller;
12use Illuminate\Support\Facades\Auth;
13
14class DepartmentsController extends Controller
15{
16 public function index()
17 {
18 return view("dashboard.departments.index")->with([
19 "departments" => Department::all()
20 ]);
21 }
22
23 public function create()
24 {
25 return view("dashboard.departments.create");
26 }
27
28 public function editShow($id)
29 {
30 return view("dashboard.departments.edit")->with([
31 "department" => Department::findOrFail($id)
32 ]);
33 }
34
35 public function edit(UpdateDepartmentRequest $request, $id)
36 {
37 $department = Department::findOrFail($id);
38
39 $department->name = $request->name;
40 $department->code = $request->code;
41
42 $department->save();
43
44 Alert::flash("Department edited successfully");
45
46 return redirect()->route("dashboard.departments.index");
47 }
48
49 public function store(NewDepartmentRequest $request)
50 {
51 $department = new Department();
52
53 $department->name = $request->name;
54 $department->code = $request->code;
55
56 $department->user_id = auth()->id();
57
58 $department->save();
59
60 Alert::flash("New Department added successfully");
61
62 return redirect()->route("dashboard.departments.index");
63 }
64
65 public function destroy(Request $request, $id)
66 {
67 $department = Department::find($id);
68
69 $department->delete();
70
71 Alert::flash($department->name . " deleted successfully");
72
73 return redirect()->route("dashboard.departments.index");
74 }
75}
Note: See TracBrowser for help on using the repository browser.