/**
  * @param int $id
  * @param Request $request
  * @return Illuminate\Http\JsonResponse
  */
 public function putIndex($id, Request $request)
 {
     $useCase = $this->useCase->find($id);
     if ($useCase) {
         $useCase->id_sistema = $request->input('id_sistema');
         $useCase->descricao = $request->input('descricao');
         $useCase->status = $request->input('status');
         $useCase->save();
         $id_revisao = $request->input('id_revisao');
         $findRevision = $this->revision->find($id_revisao);
         $findRevision->id_dados_revisao = $request->input('id_dados_revisao');
         $findRevision->id_caso_de_uso = $id;
         $findRevision->save();
         $findActor = $this->revisionActors->findByRevision($request->input('id_revisao'));
         $findActor->delete();
         foreach ($request->input('id_ator', []) as $id) {
             $r = new RevisionActors();
             $r->id_dados_revisao = $request->input('id_dados_revisao');
             $r->id_ator = $id;
             $r->id_revisao = $id_revisao;
             $r->save();
         }
     }
     return $this->getJsonResponse($id);
 }
 /**
  * @param int $id
  * @return Illuminate\Http\JsonResponse
  */
 public function deleteIndex($id)
 {
     try {
         $count = $this->revisionActor->findByActor($id)->count();
         if ($count > 0) {
             throw new \Exception('COULD_NOT_DELETE_ACTOR');
         }
         $actor = $this->actor->find($id);
         if ($actor) {
             $actor->delete();
         }
         return $this->getJsonResponse($id);
     } catch (\Exception $exception) {
         return $this->getJsonResponse(['data' => $exception->getMessage(), 'error' => true], false);
     }
 }
 /**
  * @param int $id
  * @return Illuminate\Http\JsonResponse
  */
 public function getPreview($id, UseCaseRepository $useCaseRepository)
 {
     $revision = new Revision();
     $revisionActors = new RevisionActors();
     $complementary = new \Modules\Api\Models\ComplementarySteps();
     $business = new \Modules\Api\Models\BusinessSteps();
     $reference = new \Modules\Api\Models\ReferenceSteps();
     $result = [];
     $app = new Application();
     $array = $app->where('id_sistema', $id)->get();
     foreach ($array as $application) {
         $u = $useCaseRepository->findByIdSistema($application->id_sistema);
         $a = $u->get()->toArray();
         $result['app'] = $application->toArray();
         foreach ($a as $useCaseMaroto) {
             $arrayU = $u->get()->toArray();
             foreach ($arrayU as $key => $singleUseCase) {
                 $result['app']['useCase'][$key] = $singleUseCase;
                 $revisionA = $revision->findByUseCase($singleUseCase['id_caso_de_uso'])->get()->toArray();
                 foreach ($revisionA as $revisionData) {
                     $result['app']['useCase'][$key]['revision'] = $revisionData;
                     $result['app']['useCase'][$key]['revision']['actors'] = $revisionActors->findActorByRevision($revisionData['id_revisao'])->get()->toArray();
                     $flow = $this->flow->where('id_revisao', $revisionData['id_revisao'])->get()->toArray();
                     $compl = $complementary->findByUseCase($singleUseCase['id_caso_de_uso']);
                     $bus = $business->findByUseCase($singleUseCase['id_caso_de_uso']);
                     $ref = $reference->findByUseCase($singleUseCase['id_caso_de_uso']);
                     $result['app']['useCase'][$key]['revision']['flow'][] = ['complementary' => $compl, 'business' => $bus, 'reference' => $ref];
                 }
             }
         }
     }
     return $this->getJsonResponse($result, false);
 }