PayrollHeadController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 App\Models\PayrollHead;
  14. class PayrollHeadController extends Controller
  15. {
  16. public function index()
  17. {
  18. $data['title'] = "Payroll Head List";
  19. $data['all'] = PayrollHead::orderBy('name','ASC')->get();
  20. return view('admin.payroll_head.index',$data);
  21. }
  22. public function create()
  23. {
  24. $data['title'] = "Payroll Head Create";
  25. return view('admin.payroll_head.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. $ph = new PayrollHead;
  34. $ph->name = $request->name;
  35. $ph->added_by = $user_id;
  36. $ph->status = 1;
  37. $ph->save();
  38. return redirect('admin/payroll_head')->with('msg','Data Insert Successful!');
  39. }
  40. public function edit($id)
  41. {
  42. $data['title'] = "Payroll Head Edit";
  43. $data['single'] = PayrollHead::find($id);
  44. return view('admin.payroll_head.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. $phu = PayrollHead::find($id);
  53. $phu->name = $request->name;
  54. $phu->updated_by = $user_id;
  55. $phu->save();
  56. return redirect('admin/payroll_head')->with('msg','Data Update Successful!');
  57. }
  58. public function destroy($id)
  59. {
  60. PayrollHead::whereId($id)->delete();
  61. return redirect('admin/payroll_head')->with('msg','Successfully Deleted!');
  62. }
  63. public function statusUpdate($id)
  64. {
  65. $user_id = \Auth::user()->id;
  66. $ph_info = PayrollHead::find($id);
  67. if($ph_info->status == 0){
  68. $ph_info->status = 1;
  69. $status = 'published';
  70. }else{
  71. $ph_info->status = 0;
  72. $status = 'unpublished';
  73. }
  74. $ph_info->update();
  75. }
  76. }