public function update(Request $request, $id) { $params = $request->all(); $freepost = FreePost::find($id); if ($freepost != null) { if ($request->hasFile('coverImage')) { $file = $request->file('coverImage'); $fileName = md5(uniqid()) . '.' . $file->getClientOriginalExtension(); $file->move(base_path() . '/public/upload', $fileName); $params['cover'] = '/upload/' . $fileName; } unset($params['coverImage']); if ($request->hasFile('headImage')) { $file = $request->file('headImage'); $fileName = md5(uniqid()) . '.' . $file->getClientOriginalExtension(); $file->move(base_path() . '/public/upload', $fileName); $params['head_image'] = '/upload/' . $fileName; } unset($params['headImage']); unset($params['_token']); foreach ($params as $n => $p) { $freepost->{$n} = $p; } $freepost->save(); } return redirect()->action('Admin\\FreePostController@show'); }
/** * * @SWG\Api( * path="/free_post/{id}", * description="包邮分类详情", * @SWG\Operation( * method="GET", summary="获得包邮分类详情", notes="获得包邮分类详情", * type="FreePostDetail", * @SWG\ResponseMessage(code=0, message="成功"), * @SWG\Parameter( * name="id", * description="分类id", * paramType="path", * required=true, * allowMultiple=false, * type="integer", * ) * ) * ) */ public function show(Request $request, $id) { $response = new BaseResponse(); $freePost = FreePost::find($id); $goods_list = FreePostGoods::where('free_posts_id', $id); $goods_list = $goods_list->orderBy('id', 'desc')->get(); $ret = (object) null; $ret->free_post = $freePost; $ret->goods_list = $goods_list; $response->Data = $ret; return $response->toJson(); }