Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Patrick-Jun/PopRun-b
Browse files Browse the repository at this point in the history
  • Loading branch information
SunOfMei committed May 12, 2020
2 parents c4c2cf2 + 9ff40ff commit 6d9429c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME=Laravel
APP_NAME=PopRun
APP_ENV=local
APP_KEY=
APP_DEBUG=true
Expand Down
24 changes: 20 additions & 4 deletions app/Http/Controllers/MomentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ public function delMoment(Request $request)
}
}

// 发表评论 遗留:缺少判断是否存在moid
public function doComment(Request $request)
{
if ($request->has('rid') && $request->has('moid') && $request->has('comment')) {
// 发表评论
public function doComment(Request $request){
if($request->has('rid') && $request->has('moid') && $request->has('comment')){
$comment = new Comments();
$comment->fill([
'rid' => $request->rid,
Expand Down Expand Up @@ -137,6 +136,23 @@ public function doComment(Request $request)
}
}

// 删除评论
public function delComment(Request $request){
if($request->has('coid')){
DB::beginTransaction(); //事务开始
try {
Comments::where('coid', $request->coid)->delete(); //删除评论
DB::commit(); //提交事务
return returnData(true, "操作成功", null);
} catch (\Throwable $th) {
DB::rollback(); //回滚
return returnData(false, $th);
}
}else{
return returnData(false, "缺coid", null);
}
}

// 点赞
public function doLike(Request $request)
{
Expand Down
1 change: 1 addition & 0 deletions public/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
images
medals
userImgs
files
!.gitignore
2 changes: 2 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
Route::post('/delMoment', 'MomentsController@delMoment');
// 发表评论
Route::post('/doComment', 'MomentsController@doComment');
// 删除评论
Route::get('delComment', 'MomentsController@delComment');
// 点赞
Route::post('/doLike', 'MomentsController@doLike');
// 取消点赞
Expand Down

0 comments on commit 6d9429c

Please sign in to comment.