123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Http\Controllers\Controller;
- use App\Models\QuestionModel;
- use Illuminate\Http\Request;
- class QuestionController extends Controller
- {
- /**
- * 创建问题
- * @param Request $request
- * @return array
- */
- public function create(Request $request)
- {
- $this->validate($request, [
- 'title' => 'required',
- 'content' => 'required',
- 'type' => 'required'
- ]);
- $question = new QuestionModel();
- $question->fill($request->all());
- $question->save();
- return response([
- 'code' => 200,
- 'message' => 'success'
- ]);
- }
- /**
- * 更新问题
- * @param Request $request
- * @param int $question_id
- * @return array
- */
- public function update(Request $request, int $question_id)
- {
- $question = QuestionModel::findOrFail($question_id);
- $question->fill($request->all());
- $question->save();
- return response([
- 'code' => 200,
- 'message' => 'success'
- ]);
- }
- /**
- * 删除问题
- * @param int $question_id
- * @return array
- * @throws \Exception
- */
- public function delete(int $question_id)
- {
- $question = QuestionModel::findOrFail($question_id);
- $question->delete();
- return response([
- 'code' => 200,
- 'message' => 'success'
- ]);
- }
- /**
- * 获取问题
- * @param int $question_id
- * @return array
- * @throws \Exception
- */
- public function show(int $question_id)
- {
- $question = QuestionModel::find($question_id);
- return response([
- 'code' => 200,
- 'message' => 'success',
- 'data' => $question
- ]);
- }
- /**
- * 问题列表
- * @return array
- * @throws \Exception
- */
- public function index(Request $request)
- {
- $questions = QuestionModel::get();
- return response([
- 'code' => 200,
- 'message' => 'success',
- 'data' => $questions
- ]);
- }
- }
|