我想检查用于过滤的请求是否为空,因此如果为null则显示数据表中的所有数据,否则根据请求的值过滤结果
这里控制器
public function getCustomFilterData(Request $request)
{
$arrStart = explode("/", Input::get('start_date'));
$arrEnd = explode("/", Input::get('end_date'));
$start = Carbon::create($arrStart[2], $arrStart[0], $arrStart[1], 0, 0, 0);
$end = Carbon::create($arrEnd[2], $arrEnd[0], $arrEnd[1], 23, 59, 59);
$min = $request->start_amount;
$max = $request->end_amount;
$vendorTableName= with(new Vendors())->getTable();
$categoryTableName= with(new Excategories())->getTable();
$orders =Checks::select(["checks.*","vendors.vendor_name","excategories.category_name"])->Wherebetween('amount',[$min,$max])->between($start, $end)->leftJoin($vendorTableName,$vendorTableName.".vendor_id","=","checks.vendor_id")->leftJoin($categoryTableName,$categoryTableName.".category_id","=","checks.category_id");
return Datatables::of($orders)->make( TRUE );
}
答案 0 :(得分:0)
如果您想确定请求中是否存在值且非空,则可以使用the has方法:
select: map(p, [^dynamic_value, customer: ^dynamic_value])
if ($request->has('name')) {
//
}
答案 1 :(得分:0)
虽然我有点晚了,但是如果有人想检查$request
的所有值,那么可以这样做
if( !empty($request->has( $request->all() )) ){
//the value is edited,the above condition returns true if $request has value
}
Else{
return redirect()->back()->with('warning', 'No Value Edited.');
}
在视图
中@if ($message = Session::get('success'))
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Enjoy! </strong>{{ $message }}.
</div>
@endif
@if ($message = Session::get('warning'))
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Caution! </strong>{{ $message }}.
</div>
@endif