fetch Data by Date interval this code does not work correct, i want to select by date and id
public function stock_summary(Request $request)
{
$id=$request->id;
$from=$request->from;
$to=$request->to;
$products=Products::pluck('name','id');
$inwards = CashSales::with('items')
->whereBetween('created_at', [new Carbon($from), new Carbon($to)])
->where('item_id', $id)
->get();
dd($inwards);
return view('stock_summary.show',compact('inwards','products'));
}
date format in form
'd-m-Y'
date format in DB
'Y-m-d'
how can i reverse my code and work fine
Is this the standard created_at field? In which case it is a timestamp column.
You should be able to do it as you are doing, but use carbon's createFromFormat and tell it specifically what format your dates are in (including the separator)
eg
$fromdate = Carbon::createFromFormat('d-m-Y',$from);
check these values with dd or use laravel debugbar to check the query being created.
got this error
The separation symbol could not be found Trailing data
Check the format of the string you get in the request.
@snapey ,
from string format (m-d-Y)
"01/25/2020 - 01/25/2020"
public function stock_summary(Request $request)
{
$inwards = CashSales::with('items')
->where('item_id', $request->id)
->whereBetween('created_at', [$request->from, $request->to])
->get();
dd($request->from);
HTML
<div class=" col-md-4">
<label for="from">Item Name</label>
<select class="form-control " name="id" >
<option data-tokens="">~items~</option>
@foreach($products as $key=>$type)
<option value="{{$key}}">{{$type}}</option>
@endforeach
</select>
</div>
<div class="col-md-6">
<label for="from">From</label>
<input type="text" id="from" name="from" class="daterange form-control">
</div>
am using date range
details matter
01/25/2020 is NOT m-d-Y - it is m/d/Y
so what can i do to fetch data using daterange @snapey
Please sign in or create an account to participate in this conversation.