AddressBookController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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\CompanyModel;
  7. use App\Models\AddressBookModel;
  8. class AddressBookController extends Controller
  9. {
  10. public function index()
  11. {
  12. $data['title'] = "Address Book";
  13. $data['company'] = CompanyModel::where('status',2)->orderBy('name')->get();
  14. $data['all'] = AddressBookModel::with('company')->orderBy('id','DESC')->get();
  15. return view('admin.address_book',$data);
  16. }
  17. public function create()
  18. {
  19. //
  20. }
  21. public function store(Request $request)
  22. {
  23. $name = $request->name;
  24. $designation = $request->designation;
  25. $mob1 = $request->mob1;
  26. $mob2 = $request->mob2;
  27. $email1 = $request->email1;
  28. $email2 = $request->email2;
  29. //here store request are coming form 2 side
  30. //one form address book
  31. //another is from 'admin/view_company'
  32. $company_id_form_company_indi = $request->company_id_form_company_indi;
  33. if(empty($company_id_form_company_indi))
  34. {
  35. $company_name = $request->company_name;
  36. }
  37. else{
  38. $company_name = $company_id_form_company_indi;
  39. }
  40. if(!empty($name) && !empty($mob1)){
  41. $sav = new AddressBookModel;
  42. $sav->name = $name;
  43. $sav->company_id = $company_name;
  44. $sav->designation = $designation;
  45. $sav->mob1 = $mob1;
  46. $sav->mob2 = $mob2;
  47. $sav->email1 = $email1;
  48. $sav->email2 = $email2;
  49. $sav->save();
  50. }
  51. if(empty($company_id_form_company_indi))
  52. {
  53. return redirect()->back()->with('msg', 'Data added successfully!');
  54. }
  55. else{
  56. return redirect("admin/view_company/$company_name")->with('msg', 'Data added successfully!');
  57. }
  58. }
  59. public function show($id) // show is using as destroy :(
  60. {
  61. AddressBookModel::find($id)->delete();
  62. return redirect()->back()->with('msg','Data deleted successfully');
  63. }
  64. public function edit($id)
  65. {
  66. $val = AddressBookModel::find($id);
  67. $data['id'] = $id;
  68. $data['name'] = $val->name;
  69. $data['company_name'] = $val->company_id;
  70. $data['designation'] = $val->designation;
  71. $data['mob1'] = $val->mob1;
  72. $data['mob2'] = $val->mob2;
  73. $data['email1'] = $val->email1;
  74. $data['email2'] = $val->email2;
  75. return $data;
  76. }
  77. public function update(Request $request, $id)
  78. {
  79. //
  80. }
  81. public function update_address_book(Request $request)
  82. {
  83. $id = $request->edit_id;
  84. $name = $request->edit_name;
  85. $company_name = $request->edit_company_name;
  86. $designation = $request->edit_designation;
  87. $mob1 = $request->edit_mob1;
  88. $mob2 = $request->edit_mob2;
  89. $email1 = $request->edit_email1;
  90. $email2 = $request->edit_email2;
  91. //echo "$name - $company_name - $designation - $mob1 - $mob2 - $email1 - $email2 "; die();
  92. if(!empty($name) && !empty($mob1)){
  93. $sav = AddressBookModel::find($id);
  94. $sav->name = $name;
  95. $sav->company_id = $company_name;
  96. $sav->designation = $designation;
  97. $sav->mob1 = $mob1;
  98. $sav->mob2 = $mob2;
  99. $sav->email1 = $email1;
  100. $sav->email2 = $email2;
  101. $sav->save();
  102. }
  103. return redirect()->back()->with('msg', 'Data updated successfully!');
  104. }
  105. public function destroy($id)
  106. {
  107. //
  108. }
  109. }