DesignationController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 App\Models\Designation;
  13. use Datatables;
  14. class DesignationController extends Controller
  15. {
  16. public function index()
  17. {
  18. $data['title'] = "Designation List";
  19. $data['all'] = Designation::orderBy('name','ASC')->get();
  20. return view('admin.designation.index',$data);
  21. }
  22. public function create()
  23. {
  24. $data['title'] = "Designation Create";
  25. return view('admin.designation.add',$data);
  26. }
  27. public function store(Request $request)
  28. {
  29. $this->validate($request,[
  30. 'name' => 'required'
  31. ]);
  32. $user_id = \Auth::user()->id;
  33. $designation = new Designation;
  34. $designation->name = $request->name;
  35. $designation->added_by = $user_id;
  36. $designation->status = 1;
  37. $designation->save();
  38. return redirect('admin/designation')->with('msg','Data Insert Successful!');
  39. }
  40. public function edit($id)
  41. {
  42. $data['title'] = "Designation Edit";
  43. $data['designation'] = Designation::find($id);
  44. return view('admin.designation.edit',$data);
  45. }
  46. public function update(Request $request, $id)
  47. {
  48. $this->validate($request,[
  49. 'name' => 'required'
  50. ]);
  51. $user_id = \Auth::user()->id;
  52. $designation_u = Designation::find($id);
  53. $designation_u->name = $request->name;
  54. $designation_u->updated_by = $user_id;
  55. $designation_u->save();
  56. return redirect('admin/designation')->with('msg','Data Update Successful!');
  57. }
  58. public function destroy($id)
  59. {
  60. Designation::whereId($id)->delete();
  61. return redirect('admin/designation')->with('msg','Successfully Deleted!');
  62. }
  63. public function statusUpdate($id)
  64. {
  65. $user_id = \Auth::user()->id;
  66. $designation_info = Designation::find($id);
  67. if($designation_info->status == 0){
  68. $designation_info->status = 1;
  69. $status = 'published';
  70. }else{
  71. $designation_info->status = 0;
  72. $status = 'unpublished';
  73. }
  74. $designation_info->update();
  75. }
  76. }