Esempio n. 1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $topic = Topic::findOrFail($id);
     $user = app('Dingo\\Api\\Auth\\Auth')->user();
     if (Gate::forUser($user)->denies('delete-topic', $topic)) {
         throw new AccessDeniedHttpException();
     }
     if ($topic->delete()) {
         return $this->response()->item($topic, new TopicTransformer());
     } else {
         throw new DeleteResourceFailedException('删除失败,请重新尝试');
     }
 }
Esempio n. 2
0
 public function store(SaveReplyRequest $request)
 {
     $user = app('Dingo\\Api\\Auth\\Auth')->user();
     $topic = Topic::findOrFail($request->input('topic_id'));
     $originalContent = trim($request->input('reply_content'));
     $data = array('user_id' => $user->id, 'topic_id' => $topic->id, 'original_content' => $originalContent, 'content' => (new Parser())->makeHtml($originalContent));
     $reply = Reply::create($data);
     if ($reply) {
         return $this->response()->item($reply, new ReplyTransformer());
     } else {
         throw new StoreResourceFailedException('保存失败,请重新尝试');
     }
 }
Esempio n. 3
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     $topic = Topic::findOrFail($id);
     return view('topic.edit', compact('topic'));
 }