/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['book_id' => 'required|exists:books,id']);
     $assignment = BookAssignment::create(['user_id' => $request->user()->id, 'book_id' => $request->input('book_id')]);
     AssignmentProgress::create(['assignment_id' => $assignment->id, 'num_pages_read' => 0]);
     return response(['assignment' => $assignment], 201)->header('Location', '/api/assignments/' . $assignment->id);
 }
 public function markAsRead($id)
 {
     $assignmentProgress = AssignmentProgress::find($id);
     if (!$assignmentProgress) {
         return response(['errors' => ['Assignment not existing!']], 422);
     }
     if ($assignmentProgress->is_read) {
         return response(['errors' => ['Book already marked as read!']], 422);
     }
     $assignmentProgress->update(['is_read' => true]);
     event(new StudentAssignmentEnded($assignmentProgress->id));
     return response(['progress' => AssignmentProgress::find($id)], 200);
 }