ClassroomController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\DB;
  6. /**
  7. * 大课堂
  8. * Class WorkTaskController
  9. * @package App\Http\Controllers\Admin
  10. */
  11. class ClassroomController extends Controller
  12. {
  13. public function questionsAndAnswers(Request $request)
  14. {
  15. $model = DB::table('questions_and_answers');
  16. if (!$request->ajax()) {
  17. return view('admin/classroom/questions_and_answers');
  18. }
  19. $pageSize = $request->input('pageSize') ?? 10;
  20. return $this->getList($model, $pageSize);
  21. }
  22. public function tool(Request $request)
  23. {
  24. $model = DB::table('tool');
  25. if (!$request->ajax()) {
  26. return view('admin/classroom/tool');
  27. }
  28. $pageSize = $request->input('pageSize') ?? 10;
  29. return $this->getList($model, $pageSize);
  30. }
  31. public function socialMedia(Request $request)
  32. {
  33. $model = DB::table('social_media');
  34. if (!$request->ajax()) {
  35. return view('admin/classroom/social_media');
  36. }
  37. $pageSize = $request->input('pageSize') ?? 10;
  38. return $this->getList($model, $pageSize);
  39. }
  40. public function video(Request $request)
  41. {
  42. $model = DB::table('video');
  43. if (!$request->ajax()) {
  44. return view('admin/classroom/video');
  45. }
  46. return $this->getList($model, $request->input('pageSize') ?? 10);
  47. }
  48. public function questionsAndAnswersUpdate(Request $request, $id = 0)
  49. {
  50. $model = DB::table('questions_and_answers');
  51. if (!empty($id)) {
  52. $info = $model->where('id', $id)->first();
  53. }
  54. if (!$request->ajax()) {
  55. return view('admin/classroom/questions_and_answers_update', [
  56. 'info' => $info ?? []
  57. ]);
  58. }
  59. $rules = [
  60. 'title' => 'required|max:255',
  61. 'content' => 'required',
  62. ];
  63. $message = [
  64. 'title.required' => '标题不能为空',
  65. 'content.required' => '内容不能为空',
  66. 'title.max' => '标题不能超过255个字符',
  67. ];
  68. return $this->verification($request->all(), $rules, $message, $model, $id);
  69. }
  70. public function questionsAndAnswersDelete($id = 0)
  71. {
  72. $model = DB::table('questions_and_answers');
  73. return $this->deleteInfo($model, $id);
  74. }
  75. public function toolUpdate(Request $request, $id = 0)
  76. {
  77. $model = DB::table('tool');
  78. if (!empty($id)) {
  79. $info = $model->where('id', $id)->first();
  80. }
  81. if (!$request->ajax()) {
  82. return view('admin/classroom/tool_update', [
  83. 'info' => $info ?? []
  84. ]);
  85. }
  86. $rules = [
  87. 'title' => 'required|max:255',
  88. 'content' => 'required|max:255',
  89. 'image' => 'required',
  90. 'details' => 'required',
  91. ];
  92. $message = [
  93. 'title.required' => '标题不能为空',
  94. 'content.required' => '内容不能为空',
  95. 'image.required' => '图片不能为空',
  96. 'details.required' => '详情不能为空',
  97. 'title.max' => '标题不能超过255个字符',
  98. 'content.max' => '内容不能超过255个字符',
  99. ];
  100. return $this->verification($request->all(), $rules, $message, $model, $id);
  101. }
  102. public function toolDelete($id = 0)
  103. {
  104. $model = DB::table('tool');
  105. return $this->deleteInfo($model, $id);
  106. }
  107. public function socialMediaUpdate(Request $request, $id = 0)
  108. {
  109. $model = DB::table('social_media');
  110. if (!empty($id)) {
  111. $info = $model->where('id', $id)->first();
  112. }
  113. if (!$request->ajax()) {
  114. return view('admin/classroom/social_media_update', [
  115. 'info' => $info ?? []
  116. ]);
  117. }
  118. $rules = [
  119. 'title' => 'required|max:255',
  120. 'content' => 'required|max:255',
  121. 'image' => 'required',
  122. 'details' => 'required',
  123. ];
  124. $message = [
  125. 'title.required' => '标题不能为空',
  126. 'content.required' => '内容不能为空',
  127. 'image.required' => '图片不能为空',
  128. 'details.required' => '详情不能为空',
  129. 'title.max' => '标题不能超过255个字符',
  130. 'content.max' => '内容不能超过255个字符',
  131. ];
  132. return $this->verification($request->all(), $rules, $message, $model, $id);
  133. }
  134. public function socialMediaDelete($id = 0)
  135. {
  136. $model = DB::table('social_media');
  137. return $this->deleteInfo($model, $id);
  138. }
  139. public function videoUpdate(Request $request, $id = 0)
  140. {
  141. $model = DB::table('video');
  142. if (!empty($id)) {
  143. $info = $model->where('id', $id)->first();
  144. }
  145. if (!$request->ajax()) {
  146. return view('admin/classroom/video_update', [
  147. 'info' => $info ?? []
  148. ]);
  149. }
  150. $rules = [
  151. 'title' => 'required|max:255',
  152. 'user' => 'required|max:255',
  153. 'image' => 'required',
  154. 'video' => 'required|max:255',
  155. ];
  156. $message = [
  157. 'title.required' => '标题不能为空',
  158. 'user.required' => '发布者姓名不能为空',
  159. 'image.required' => '图片不能为空',
  160. 'video.required' => '视频链接不能为空',
  161. 'title.max' => '标题不能超过255个字符',
  162. 'user.max' => '发布者姓名不能超过255个字符',
  163. ];
  164. return $this->verification($request->all(), $rules, $message, $model, $id);
  165. }
  166. public function videoDelete($id = 0)
  167. {
  168. $model = DB::table('video');
  169. return $this->deleteInfo($model, $id);
  170. }
  171. }