Laravel Datepicker和雄辩的查询 [英] Laravel Datepicker And Eloquent Query
问题描述
我正在制作一个页面,我可以使用日期游侠,jqueryui.com的datepicker,我非常喜欢laravel框架。
I am making a page where I can use the date ranger, datepicker from jqueryui.com and i am very mewbie to laravel Framework.
我有雄辩的查询如下,
public function orderbydate()
{
$order =DB::table('sales_flat_order_items as s')
->leftJoin('sales_flat_orders as w', 'w.entity_id','=','s.order_id')
->select(array(DB::Raw('sum(s.amount_refunded) as amount_refunded'),
DB::Raw('sum(s.row_total) as row_total'),
DB::Raw('sum(s.discount_amount) as discount_amount'),
DB::Raw('sum(s.tax_amount) as tax_amount'),
DB::Raw('sum(s.qty_ordered) as qty_ordered'),
DB::Raw('sum(w.subtotal) as subtotal'),
DB::Raw('sum(w.total_invoiced) as total_invoiced'),
DB::Raw('sum(w.shipping_amount) as shipping_amount')))
->where('qty_canceled','=','0')
->where('status','!=','canceled')
->get();
$orderbydate = DB::table('sales_flat_order_items as s')
->leftJoin('sales_flat_orders as w', 'w.entity_id','=','s.order_id')
->select(array(DB::Raw('sum(s.amount_refunded) as amount_refunded'),
DB::Raw('sum(s.row_total) as row_total'),
DB::Raw('sum(s.discount_amount) as discount_amount'),
DB::Raw('sum(s.tax_amount) as tax_amount'),
DB::Raw('sum(s.qty_ordered) as qty_ordered'),
DB::Raw('sum(w.subtotal) as subtotal'),
DB::Raw('DATE(w.created_at) days'),
DB::Raw('sum(w.total_invoiced) as total_invoiced'),
DB::Raw('sum(w.shipping_amount) as shipping_amount')))
->where('qty_canceled','=','0')
->where('status','!=','canceled')
->groupBy('days')
->orderBy('s.created_at')
->paginate(10);
return View::make('sales_flat_orders.orderbydate', compact('order','orderbydate'));
}
注意:此功能将显示模板上的所有数据
Note: this function will show u all the data on the template
另一个功能是
public function orderbydate1()
{
$startDate = Input::get('w.created_at');
$endDate = Input::get('w.created_at');
$order1 =DB::table('sales_flat_order_items as s')
->leftJoin('sales_flat_orders as w', 'w.entity_id','=','s.order_id')
->select(array(DB::Raw('sum(s.amount_refunded) as amount_refunded'),
DB::Raw('sum(s.row_total) as row_total'),
DB::Raw('sum(s.discount_amount) as discount_amount'),
DB::Raw('sum(s.tax_amount) as tax_amount'),
DB::Raw('sum(s.qty_ordered) as qty_ordered'),
DB::Raw('sum(w.subtotal) as subtotal'),
DB::Raw('sum(w.total_invoiced) as total_invoiced'),
DB::Raw('sum(w.shipping_amount) as shipping_amount')))
->where('qty_canceled','=','0')
->where('status','!=','canceled')
->get();
$orderbydate1 = DB::table('sales_flat_order_items as s')
->leftJoin('sales_flat_orders as w', 'w.entity_id','=','s.order_id')
->select(array(DB::Raw('sum(s.amount_refunded) as amount_refunded'),
DB::Raw('sum(s.row_total) as row_total'),
DB::Raw('sum(s.discount_amount) as discount_amount'),
DB::Raw('sum(s.tax_amount) as tax_amount'),
DB::Raw('sum(s.qty_ordered) as qty_ordered'),
DB::Raw('sum(w.subtotal) as subtotal'),
DB::Raw('DATE(w.created_at) days'),
DB::Raw('sum(w.total_invoiced) as total_invoiced'),
DB::Raw('sum(w.shipping_amount) as shipping_amount')))
->whereBetween('w.created_at',array($startDate,$endDate))
->where('qty_canceled','=','0')
->where('status','!=','canceled')
->groupBy('days')
->orderBy('s.created_at')
->paginate(10);
return View::make('sales_flat_orders.result', compact('order','orderbydate1'));
}
我有模板命名为 OrderByDAte.blade.php
{{ Form::open() }}
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">
<input type="submit" value="Submit" class="btn btn-info btn-block">
{{ Form::close() }}
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
</script>
还有显示表格的循环。
现在
**result.blade.php** which displays the data.
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr class="odd gradeX">
<th>DATE</th>
<th>Items Ordered</th>
<th>Subtotal</th>
<th>Tax Amount</th>
<th>Discount Amount</th>
<th>Row Total</th>
<th>Refunded</th>
<th>Total Invoiced</th>
<th>Shipping Amount</th>
</tr>
</thead>
@foreach($orderbydate1 as $s)
<tbody>
<tr class="odd gradeX">
<td>{{date("d F, Y",strtotime($s->days))}}</td>
<td>{{ round($s->qty_ordered, 2) }}</td>
<td>{{round($s->subtotal,2)}}</td>
<td>{{round($s->tax_amount,2)}}</td>
<td>{{round($s->discount_amount,2)}}</td>
<td>{{round($s->row_total,2)}}</td>
<td>{{round($s->amount_refunded,2)}}</td>
<td>{{round($s->total_invoiced,2)}}</td>
<td>{{round($s->shipping_amount,2)}}</td>
</tr>
@endforeach
注意:我的提交按钮不起作用我不知道为什么?
Note: I think my Submit Button Does not works. I dnt know why?
现在我想使用datepicker过滤这个日期,在我的路线,我知道我必须使用帖子,并提交日期后,我必须获取该范围内的数据。
Now I want to use datepicker to filter this by date, in my routes i know that i have to use post and after submitting the date i must get the datatable in that range.
如何在这里使用$ startDate和$ endDate。在我雄辩的查询中。我必须为$ startDate输入'w.created_at'字段,并为$ endDate输入'w.created_at'。
我想我必须在我的函数中使用外观输入,如下所示。
How to use $startDate and $endDate over here. in my eloquent query. I have to take input 'w.created_at' field for my startDate and also 'w.created_at' for $endDate. I think i have to use facade input in my function like this.
$startDate = Input::get('w.created_at');
$endDate = Input::get('w.created_at');
但是这个功能不起作用。
But this function does not work.
我正在使用引导日期戳。但是,如果你知道其他的,那么U可以给我举个例子。
I am currently using the bootstrap datepicker. But if you know other one then U can give me examples for it.
现在有两个我用于
Route::get('orderbydate', array('as'=>'orderbydate', 'uses'=>'SalesFlatController@orderbydatesales'))
将所有数据导入我的模板。
to get all the data into my template.
对于该帖子,我使用
Route::get('result', array('as'=>'result', 'uses'=>'SalesFlatController@orderbydate'))
注意: / strong>我收到一个错误,如Missing 1参数。
Note: I get an error like Missing 1 argument.
任何人只要帮我一点,只是知道我在哪里错了?
Can anyone just help me a little in just knowing where i am going wrong??
推荐答案
您需要更改:
public function orderbydate($startDate, $endDate)
to:
public function orderbydate()
您从 Input :: get()
中获取这些值时
。只有当这些变量来自路由中的变量时,才会将这些变量放在函数调用中,即:
as you're getting those values from Input::get()
. You'd put those variables in the function call only if those variables were coming from variables in the route, i.e.:
Route::get('result/{startDate}/{endDate}', array('as'=>'result', 'uses'=>'SalesFlatController@orderbydate'))
这篇关于Laravel Datepicker和雄辩的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!