Exemplo n.º 1
0
 public function getSubjectItemAttribute()
 {
     if ($this->type == 1) {
         return Subject::find($this->item_id)->toArray();
     } else {
         return null;
     }
 }
Exemplo n.º 2
0
 /**
  *
  * @SWG\Api(
  *   path="/subject/{id}",
  *   description="获取专题题详情",
  *   @SWG\Operation(
  *     method="GET", summary="获取专题题详情", notes="获取专题题详情",
  *     type="Subject",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="id",
  *         paramType="path",
  *         required=true,
  *         allowMultiple=false,
  *         type="integer",
  *     )
  *   )
  * )
  */
 public function show($id)
 {
     $response = new BaseResponse();
     $subject = Subject::find($id)->toArray();
     $themes = $subject['themes'];
     $subjects['themes'] = [];
     foreach ($themes as $t) {
         array_push($subjects['themes'], $t['themes'][0]);
     }
     $ret['item'] = $subjects;
     $response->Data = $ret;
     return $response->toJson();
 }
Exemplo n.º 3
0
 public function getItemAttribute()
 {
     if ($this->type == 0) {
         $subjects = Subject::find($this->item_id);
         if ($subjects == null) {
             return null;
         }
         $subjects = $subjects->toArray();
         $themes = $subjects['themes'];
         $subjects['themes'] = [];
         foreach ($themes as $t) {
             array_push($subjects['themes'], $t['themes'][0]);
         }
         return $subjects;
     } else {
         $themes = Themes::find($this->item_id);
         if ($themes == null) {
             return null;
         }
         return $themes->toArray();
     }
 }
Exemplo n.º 4
0
 public function delete($id)
 {
     $home = Home::where('item_id', $id)->where('type', 0)->first();
     if ($home != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该专题已绑定到首页,对应id为' . $home->id;
         echo json_encode($ret);
         return;
     }
     Subject::find($id)->delete();
     $ret['meta']['code'] = 1;
     echo json_encode($ret);
 }