使用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>
答案 0 :(得分:1)
在routes.php
中添加Route::post('comments_post/{commentcounter}', '{your Controller}@{your view}');
它会向你的控制器发送id,你就可以使用
了答案 1 :(得分:1)
Route :: get('comments_post / {commentcounter}','yourController @ commentcountIncrement');
href =“{!! 动作( “yourController @ commentcountIncrement”,[ “commentcounter”=&GT; $&后GT;标识 ])!!}“