コード例 #1
0
 /**
  * delete comment
  * @author  Tran Van Moi
  * @since  2015/05/20    	
  * @return int
  */
 public function deleteDelete()
 {
     $data = Input::all();
     $rules = ['cmt_id' => 'required|exists:comments,id'];
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         return 404;
     } else {
         $check_role_cmt = Comment::whereId($data['cmt_id'])->whereDelete_status(0)->first();
         $check_role_post = Post::whereUser_id(Auth::user()->id)->whereId($check_role_cmt->post_id)->first();
         if ($check_role_cmt->user_id == Auth::user()->id || $check_role_post) {
             $check_role_cmt->delete_status = 1;
             $check_role_cmt->save();
             return 200;
         } else {
             return 404;
         }
     }
 }
コード例 #2
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $commentId = $this->route('comment');
     $user = JWTAuth::parseToken()->authenticate();
     return Comment::whereId($commentId)->whereUserId($user->id)->exists();
 }
コード例 #3
0
ファイル: CommentController.php プロジェクト: elberd/maoh
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function remove($id)
 {
     if (Auth::check()) {
         $comment = Comment::whereId($id)->first();
         if ($comment === null) {
             $ad_id = Request::input('ad');
         } else {
             $ad_id = $comment->ad_id;
             $user_id = Auth::user()->id;
             if ($user_id == $comment->author_id || $user_id == $comment->ad->author->id) {
                 $comment->delete();
             }
         }
         return view('sub.comments', ['ad' => Ad::getById($ad_id), 'comments' => Comment::getByAdId($ad_id)]);
     }
 }
コード例 #4
0
 public function update(Request $request)
 {
     $pk = $request->input('pk');
     $comment = Input::get('value');
     $commentData = Comment::whereId($pk)->first();
     $commentData->comment = $comment;
     if ($commentData->save()) {
         return Response::json(array('status' => 1));
     } else {
         return Response::json(array('status' => 0));
     }
 }