The problem I'm having is that after I've selected a date range and the page refreshes and the date that I selected is not showing. I'm using livewire
Here is my code
<div id="reportrange" wire:model="rangeDate" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%; height: 36px; border-radius: 5px; margin-top: 4px; overflow: hidden;">
<i class="fa fa-calendar"></i>
<span wire:model="rangeDate"></span> <i class="fa fa-caret-down"></i>
<input type="hidden" id="startDate" wire:model="startDate">
<input type="hidden" id="endDate" wire:model="endDate">
</div>
<script type="text/javascript">
$(function() {
var start = moment();
var end = moment();
function cb(start, end) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, function(start, end){
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
@this.set('startDate', start.format('YYYY-MM-DD'));
@this.set('endDate', end.format('YYYY-MM-DD'));
}, cb);
cb(start, end);
});
</script>
and this is my Index.php
<?php
namespace App\Http\Livewire\Products;
use App\Models\Product;
use Livewire\Component;
class Index extends Component
{
public $startDate = '';
public $endDate = '';
public $rangeDate;
public function render()
{
$products = Product::whereBetween('created_at', [$this->startDate, $this->endDate]);
$this->rangeDate = $this->startDate;
return view('livewire.products.index', ['products' => $products]);
}
}