使用Laravel和sqlite,我试图增加一个值,该值表示下一页上有多少评论。我遇到的问题是需要递增的值在按钮中作为"标签",所以我无法使用 Input::get('commentCounter')
从中提取值。
以下是我删除和发表评论时调用的函数:
function commentcountdelete($id){
$commentcounter = Input::get('commentcounter');
$sql = "Update status Set commentCount = ?-1 WHERE id = ?";
$results = DB::update ($sql, array($commentcounter,$id));
return $results;
}
function commentcountIncrement($id){
$commentcounter = Input::get('commentcounter');
$sql = "Update status Set commentCount = ?+1 WHERE id = ?";
$results = DB::update ($sql, array($commentcounter,$id));
return $results;
}
下面是需要从中提取值的位置:
<a href ="{{{ url("comments_post/$post->Id") }}}"><button id="commentBTN" type="button" class="btn btn-default">Comments: {{{$post->commentCount}}}</button></a>
在路由中添加此内容.php
Route::post('comments_post/{commentcounter}', '{your Controller}@{your view}');
它会将 id 发送到您的控制器,您将能够使用它
- 请确保在路由.php文件中
路由::get('comments_post/{commentcounter}', 'yourController@commentcountIncrement');
- 在链接中,我们应该使用操作而不是URL它会像
href ="{!! action("yourController@commentcountIncrement",["commentcounter"=>$post->Id ] ) !!}"