Пример #1
0
 /**
  * latest context pull api.
  *
  * @param  Request $request
  *
  * @return json
  */
 public function index(Request $request)
 {
     $data = $this->tag->getList()->toArray();
     if (!$data) {
         return $this->response->errorInternalError();
     }
     return $this->response->withArray(array_values($data));
 }
Пример #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int      $id
  * @return Response
  */
 public function destroy($id)
 {
     if ($this->tag->delete($id)) {
         return redirect('tag')->with('success', 'Tag successfully deleted!');
     }
     return redirect('tag')->with('error', 'Error deleting Tag !');
 }
Пример #3
0
 /**
  * @param $id
  * @param $formData
  * @return bool
  */
 public function update($id, $formData)
 {
     $tags = [];
     if (isset($formData['tag'])) {
         $tags = $this->tag->createOrGet($formData['tag']);
     }
     $this->database->beginTransaction();
     try {
         $question = $this->find($id);
         if (!$question->update($formData)) {
             return false;
         }
         $question->tags()->sync($tags);
         $this->saveAnswers($formData, $question);
         $this->saveSubQuestions($formData, $question);
         $this->database->commit();
         return $question;
     } catch (\Exception $e) {
         dd($e);
         $this->database->rollback();
         return false;
     }
     $this->database->rollback();
     return false;
 }
Пример #4
0
 /**
  * @param $id
  * @param $formData
  *
  * @return bool
  */
 public function update($id, $formData)
 {
     $tags = [];
     if (isset($formData['tag'])) {
         $tags = $this->tag->createOrGet($formData['tag']);
     }
     $this->database->beginTransaction();
     try {
         $formData['is_published'] = isset($formData['is_published']) ? true : false;
         $post = $this->find($id);
         $post->created_at = $formData['created_at'];
         if (isset($formData['metadata']['data']['phone'])) {
             $formData['metadata']['data']['phone'] = array_values($formData['metadata']['data']['phone']);
         }
         if ($formData['metadata']['type'] === 'text') {
             $formData = $this->formatTypeTextUpdate($post, $formData);
         }
         if ($formData['metadata']['type'] === 'audio') {
             $formData = $this->formatTypeAudioUpdate($post, $formData);
         }
         if ($formData['metadata']['type'] === 'video') {
             $formData = $this->getVideoData($formData);
         }
         if (isset($formData['metadata']['featured_image'])) {
             $this->file->delete($this->uploadPath . '/' . $post->metadata->featured_image);
             $formData['metadata']['featured_image'] = $this->upload($formData['metadata']['featured_image']);
         } else {
             $formData['metadata']['featured_image'] = isset($post->metadata->featured_image) ? $post->metadata->featured_image : '';
         }
         if (!$post->update($formData)) {
             return false;
         }
         $this->updateRelations($formData, $post);
         $post->tags()->sync($tags);
         $this->database->commit();
         return $post;
     } catch (\Exception $e) {
         $this->logger->error($e);
         $this->database->rollback();
         return false;
     }
     $this->database->rollback();
     return false;
 }