laravel中的sqlite行数据增量

时间:2015-04-20 03:28:04

标签: php sqlite laravel

使用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>

2 个答案:

答案 0 :(得分:1)

在routes.php

中添加
Route::post('comments_post/{commentcounter}', '{your Controller}@{your view}');

它会向你的控制器发送id,你就可以使用

答案 1 :(得分:1)

  1. 请确认route.php文件
  2.   

    Route :: get('comments_post / {commentcounter}','yourController @ commentcountIncrement');

    1. 在链接中我们应该使用action而不是url 它会像
    2.   

      href =“{!!   动作( “yourController @ commentcountIncrement”,[ “commentcounter”=&GT; $&后GT;标识   ])!!}“