Live pull data from database in laravel

 


Main blade view

<h1>
  The current count is 
  <span id="mycount">
    {{ Facility::where('aID',$this->id)->where('type',$type)->count(); }}
  </span>
</h1>

jQuery

function getCount() {

    $.ajax({
      type: "GET",
      url: "{{ route('route_for_new_data_here') }}"
    })
    .done(function( data ) {
      $('#mycount').html(data);

      setTimeout(getCount, 1000);
    });
}
getCount();

Controller

In a controller, you'll need something then to work with this and send back the count

function getCount()
{
    echo Facility::where('aID',$this->id)->where('type',$type)->count();
}

Post a Comment

أحدث أقدم