<?php

namespace App\Http\Controllers\Api;

use App\Answers;
use App\Members;
use App\UserAnswers;
use Illuminate\Http\Request;

class UserAnswersController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return array
     */
    public function index()
    {
        $news = Answers::query()->get()->toArray();

        return $this->ok($news);
    }
    //获取某个同学的答题结果
   public function show($id){
        $data = UserAnswers::query()->where(['users_id' => $id])->get()->toArray();
        return $this->ok($data);
   }
   public function post_answer($id, Request $request){
        $user = Members::query()->find($id)->toArray();
        $insertData = [
            'users_id' => $id,
            'nickname' => $user['nickname'],
            'score' => $request->input('score'),
            'true_num' => $request->input('true_num'),
            'false_num' => $request->input('false_num'),
//            'detail' => json_encode($request->input('detail'))
        ];
        UserAnswers::query()->create($insertData);
        return $this->ok([]);
   }
}
