0

Using Laravel and sqlite I'm trying to increment a value that represents how many comments are on the next page. The problem I'm having is the value that needs to be incremented is in a button as the "label" so I can't pull the value from it using Input::get('commentCounter').

Here are the functions that are called when I delete and post a comment:

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;
}

Here's where the value needs to be extracted from:

<a href ="{{{ url("comments_post/$post->Id") }}}"><button id="commentBTN" type="button" class="btn btn-default">Comments: {{{$post->commentCount}}}</button></a>

2 Answers 2

1

Add this in routes.php

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

It will send id to your controller and you will be able to use that

Sign up to request clarification or add additional context in comments.

Comments

1
  1. Please Make sure in route.php file

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

  1. in the link we should use action instead of url it will be like

href ="{!! action("yourController@commentcountIncrement",["commentcounter"=>$post->Id ] ) !!}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.