GradeController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Employee;
  7. use App\Models\EmployeeEducation;
  8. use App\Models\EmployeeDocument;
  9. use App\Models\EducationLevel;
  10. use App\Models\DocumentType;
  11. use App\Models\Grade;
  12. use Validator;
  13. class GradeController extends Controller
  14. {
  15. public function index()
  16. {
  17. $data['title'] = "Grade List";
  18. $data['all'] = Grade::with(['gradeAmount'])->orderBy('name','ASC')->get();
  19. return view('admin.grade.index',$data);
  20. }
  21. public function create()
  22. {
  23. $data['title'] = "Grade Create";
  24. return view('admin.grade.add',$data);
  25. }
  26. public function store(Request $request)
  27. {
  28. $validator = Validator::make($request->all(), [
  29. 'name' => 'required'
  30. ]);
  31. if ($validator->passes()) {
  32. $user_id = \Auth::user()->id;
  33. $grade = new Grade;
  34. $grade->name = $request->name;
  35. $grade->added_by = $user_id;
  36. $grade->status = 1;
  37. $grade->save();
  38. return redirect('admin/grade')->with('msg','Data Insert Successful!');
  39. }
  40. return response()->json(['error'=>$validator->errors()->all()]);
  41. }
  42. public function edit($id)
  43. {
  44. $data['title'] = "Grade Edit";
  45. $data['grade'] = Grade::find($id);
  46. return view('admin.grade.edit',$data);
  47. }
  48. public function update(Request $request, $id)
  49. {
  50. $this->validate($request,[
  51. 'name' => 'required'
  52. ]);
  53. $user_id = \Auth::user()->id;
  54. $grade_u = Grade::find($id);
  55. $grade_u->name = $request->name;
  56. $grade_u->updated_by = $user_id;
  57. $grade_u->save();
  58. return redirect('admin/grade')->with('msg','Data Update Successful!');
  59. }
  60. public function destroy($id)
  61. {
  62. Grade::whereId($id)->delete();
  63. return redirect('admin/grade')->with('msg','Successfully Deleted!');
  64. }
  65. public function statusUpdate($id)
  66. {
  67. $user_id = \Auth::user()->id;
  68. $grade_info = Grade::find($id);
  69. if($grade_info->status == 0){
  70. $grade_info->status = 1;
  71. $status = 'published';
  72. }else{
  73. $grade_info->status = 0;
  74. $status = 'unpublished';
  75. }
  76. $grade_info->update();
  77. }
  78. }