public function getSubjectItemAttribute() { if ($this->type == 1) { return Subject::find($this->item_id)->toArray(); } else { return null; } }
/** * * @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(); }
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(); } }
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); }