Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     $article = new Article();
     $splitter = new ImageSplitter($request->request->get('article_content'));
     if ($splitter->is_matched) {
         for ($i = 0; $i < $splitter->is_matched; $i++) {
             $res = new UploadedRes();
             $img = $splitter->getImageContent()[$i];
             $res->filename = MyUtil::save_file($img);
             $res->mime = $splitter->getMime()[$i];
             $res->save();
             $arr_id[] = $res->id;
         }
         $article->content = $splitter->getPlainContent($arr_id);
     } else {
         $article->content = $request->request->get('article_content');
     }
     $article->title = $request->request->get('article_title');
     $article->category = $request->request->get('article_category');
     $article->save();
     //        return response()->json(array("success" => "1", "new_id" => 1), 200,
     //            array('Content-Type:text/json;charset=UTF-8'));
     return response()->json(array("success" => "1", "new_id" => $article->id), 200, array('Content-Type:text/json;charset=UTF-8'));
 }
Ejemplo n.º 2
0
 public static function get_res_file($content)
 {
     //<img src="{@res_id=3}"
     $matched = preg_match('/<img\\ssrc="{@res_id=(?P<resId>\\d+)}">/', $content, $matches);
     if ($matched) {
         $res = UploadedRes::find($matches["resId"]);
         return $res->filename;
     }
     return null;
 }
Ejemplo n.º 3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     DB::connection()->getPdo()->beginTransaction();
     try {
         $teachers = Teacher::find($id);
         $resId = $teachers->photo;
         $teachers->delete();
         UploadedRes::destroy($resId);
         DB::connection()->getPdo()->commit();
         return response()->json(array("ok" => 1), 200, ['Content-Type:text/json;charset=UTF-8']);
     } catch (\PDOException $e) {
         DB::connection()->getPdo()->rollback();
         return response()->json(array("ok" => 0), 500, ['Content-Type:text/json;charset=UTF-8']);
     }
 }