vendredi 22 mai 2020

Why date in human difference not working properly

I am using laravel and jquery to make a simple commenting system. and things working fine but the date showing for comments or reply, what i am fetching from mysqli database is also fine but showing *Posted 5 hour ago * for every new comment or reply.

My php code is

<div class="comment-box" id="comment_box">
<?php   
foreach ($comments as $comment):     
if($comment->video_id == $content_record->code && $comment->comment_type == 1){                 
?>
    <div class="comment" id="comment<?php echo $comment['user_id']; ?>">
        <div class="author-thumbnail">
          <img src="" alt="<?= $comment['video_id'] 
          ?>">
        </div>
        <div class="comment-text"><strong>
          <?= $comment['user_id'] ?></strong> - posted
             
        </div>
        <div class="text">
            
        </div>
    </div>

    <?php  
    foreach ($replys as $reply):
      if($reply->video_id == $content_record->code && $reply->replay_for == $comment->id){
    ?>
      <div class="comment coment-replay">
        <div class="author-thumbnail">
           <img src="" alt=""></div>
              <div class="comment-text"><strong><?php  echo $reply['user_id']; ?></strong> - posted
                   
              </div>
               <div class="text">
                   
              </div>
          </div>
      <?php 
      }
    endforeach; 

    ?>
    <?php   
       // if(($replys_method =='both' || $replys_method =='ovoo')) :
    ?>
    <div class="comment coment-replay">
        <form>
            <textarea name="reply" id="reply_" class="form-control" rows="2" placeholder="Repay" required></textarea>
           <input type="hidden" name="video_id1" value="">
            <input type="hidden" id="reply_for_" name="url1" value="">
            <input type="hidden" name="comment_type1" id="comment_type1" value="2">
            <input type="hidden" name="publication1" id="publication1" value="1">
            <div>
              <?php 
              $user = auth()->user();
              if(!empty($user->id))
              { 
              ?>
               <button type="submit" value="submit" class="btn btn-success btn-sm pull-right reply "> 
                    <span class="btn-label"><i class="fi ion-ios-undo-outline"></i></span>
                    Replay 
               </button>
                <?php }else{ ?>

                <a class="btn btn-success" href=""> 
                    <span class="btn-label">
                        <i class="fi ion-log-in"></i>
                    </span>
                    Login to Replay  
                </a>
                <?php } ?>
            </div>
        </form> 
    </div> 
    <script type="text/javascript">
      $(".reply").click(function(e){
          e.preventDefault();
          var namer        = '';
          var passwordr    = $("#reply_for_").val();
          var comntr       = $("#reply_").val();
          var comnttyper   = $("#comment_type1").val();
          var publicationr = $("#publication1").val();
          var tokenr       = '';

          $.ajax({
            type:'POST',
            url: '',
            data:{video_id:namer, url:passwordr, comment:comntr, _token:tokenr, publication:publicationr, comment_type:comnttyper},
            success:function(data){

              alert('Your comment has been post wait for approval');
              console.log(data);
              $("#reply").val("");
            },
            error: function (error) {
              alert('Please Login First Before Comment.');
            }
          });
        });
    </script>
    <?php 

    }
    // endif; 
    endforeach; 

    if($total_comments == 0){
      echo "<style> #comment-container{margin-top:0px !important} </style>";  
    }else{
    echo "<style> #comment-container{margin-top:50px !important} </style>";  
    }

    ?>

And jquery i am using for this is

<script>
  function sendMessage() {
var messageBody = document.querySelector('.msg_card_body');
messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight;
// get message
var message = document.getElementById("message").value;
// save in database
firebase.database().ref("messages").push().set({
  "sender": myName,
  "message": message,
  "video_id": '',
  "student": "yes",
  "datetime": '',
  "senderphoto": '',
  "date"    : ''
});
 document.getElementById("message").value = "";
// prevent form from submitting
return false;

}

but getting wrong date while date in database is inserting perfect.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3eg6uWd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire