VocabularyController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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\User;
  7. use Auth;
  8. use DB;
  9. use App\Models\Vocabulary;
  10. use App\Models\Vocabulary_questions;
  11. class VocabularyController extends Controller
  12. {
  13. public function __construct()
  14. {
  15. $this->middleware('auth');
  16. }
  17. /**
  18. * Display a listing of the resource.
  19. *
  20. * @return \Illuminate\Http\Response
  21. */
  22. public function index(Request $request)
  23. {
  24. date_default_timezone_set("Asia/Dhaka");
  25. $all_vocabularies=Vocabulary::orderBy('id','DESC')->paginate(15);
  26. return view('admin.vocabulary.index',compact('all_vocabularies'))->with('i', ($request->input('page', 1) - 1) * 15);
  27. }
  28. /**
  29. * Show the form for creating a new resource.
  30. *
  31. * @return \Illuminate\Http\Response
  32. */
  33. public function create()
  34. {
  35. //
  36. }
  37. /**
  38. * Store a newly created resource in storage.
  39. *
  40. * @param \Illuminate\Http\Request $request
  41. * @return \Illuminate\Http\Response
  42. */
  43. public function store(Request $request)
  44. {
  45. //
  46. }
  47. /**
  48. * Display the specified resource.
  49. *
  50. * @param int $id
  51. * @return \Illuminate\Http\Response
  52. */
  53. public function show($id)
  54. {
  55. //
  56. }
  57. /**
  58. * Show the form for editing the specified resource.
  59. *
  60. * @param int $id
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function edit($id)
  64. {
  65. $item = Vocabulary::find($id);
  66. $meaning_ques = Vocabulary_questions::where('word_id','=',$id)->where('level','=',1)->pluck('question')->first();
  67. $meaning_opt = Vocabulary_questions::where('word_id','=',$id)->where('level','=',1)->pluck('options')->first();
  68. $syn_ques = Vocabulary_questions::where('word_id','=',$id)->where('level','=',2)->pluck('question')->first();
  69. $syn_opt = Vocabulary_questions::where('word_id','=',$id)->where('level','=',2)->pluck('options')->first();
  70. $anto_ques = Vocabulary_questions::where('word_id','=',$id)->where('level','=',3)->pluck('question')->first();
  71. $anto_opt = Vocabulary_questions::where('word_id','=',$id)->where('level','=',3)->pluck('options')->first();
  72. return view('admin.vocabulary.edit',compact('item','meaning_ques','syn_ques','syn_opt','meaning_opt','anto_ques','anto_opt'));
  73. }
  74. /**
  75. * Update the specified resource in storage.
  76. *
  77. * @param \Illuminate\Http\Request $request
  78. * @param int $id
  79. * @return \Illuminate\Http\Response
  80. */
  81. public function update(Request $request)
  82. {
  83. $id=$request->hdn_id;
  84. $vocabulary=Vocabulary::find($id);
  85. $vocabulary->word=$request->word;
  86. $vocabulary->meaning=$request->meaning;
  87. $vocabulary->synonyms=$request->syn;
  88. $vocabulary->antonyms=$request->antonym;
  89. $vocabulary->example=$request->example;
  90. $vocabulary->save();
  91. $v_ques1= new Vocabulary_questions();
  92. $v_ques1->question="What is the meaning of the word {$vocabulary->word}?";
  93. $v_ques1->options=strip_tags($request->meaning_opt);
  94. $v_ques1->level=1;
  95. $v_ques1->word_id=$id;
  96. $v_ques1->display=1;
  97. $v_ques1->updated_at=date('Y-m-d H:i:s');
  98. $v_ques1->save();
  99. $v_ques2= new Vocabulary_questions();
  100. $v_ques2->question="What is the synonym of the word {$vocabulary->word}?";
  101. $v_ques2->options=strip_tags($request->syn_opt);
  102. $v_ques2->level=2;
  103. $v_ques2->word_id=$id;
  104. $v_ques2->display=1;
  105. $v_ques2->updated_at=date('Y-m-d H:i:s');
  106. $v_ques2->save();
  107. $v_ques3= new Vocabulary_questions();
  108. $v_ques3->question="What is the antonym of the word {$vocabulary->word}?";
  109. $v_ques3->options=strip_tags($request->anto_opt);
  110. $v_ques3->level=3;
  111. $v_ques3->word_id=$id;
  112. $v_ques3->display=1;
  113. $v_ques3->updated_at=date('Y-m-d H:i:s');
  114. $v_ques3->save();
  115. return redirect()->action('Admin\VocabularyController@index');
  116. }
  117. /**
  118. * Remove the specified resource from storage.
  119. *
  120. * @param int $id
  121. * @return \Illuminate\Http\Response
  122. */
  123. public function destroy($id)
  124. {
  125. //
  126. }
  127. }