Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用日期选择器通过Laravel Collective获取搜索结果_Php_Laravel_Laravelcollective - Fatal编程技术网

Php 使用日期选择器通过Laravel Collective获取搜索结果

Php 使用日期选择器通过Laravel Collective获取搜索结果,php,laravel,laravelcollective,Php,Laravel,Laravelcollective,[修改的问题] 下面是使用数据选择器搜索数据的代码 在前/头中 <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script type="text/javascript"> $("#datepicker_f

[修改的问题]

下面是使用数据选择器搜索数据的代码

在前/头中

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript">
    $("#datepicker_from").datepicker({
        changeMonth: true,
        changeYear: true,
        format: 'DD-MM-YYYY',
        startDate: '01-10-2017',
       onSelect: function (dateText) {
         $("#datepicker_to").datepicker('option', 'minDate', dateText);
       }
    });
    $("#datepicker_to").datepicker({
        changeMonth: true,
        changeYear: true,
        format: 'DD-MM-YYYY',
        endDate: '01-11-2017',
    });
</script>
控制器

public function login_history_search(Request $request) 
  { 
  $histories = DB::table('loginhistories')
  ->where('created_at','>=', Carbon::parse($request->input('datepicker_from'))->format('Y-m-d'))
  ->orWhere('created_at','<=', Carbon::parse($request->input('datepicker_to'))->format('Y-m-d')) 
  ->get(); 
  return view('profiles.login_histories', ['histories' => $histories]); 
  }
公共功能登录\u历史\u搜索(请求$Request)
{ 
$histories=DB::table('loginhistories')
->其中('created_at','>=',Carbon::parse($request->input('datepicker_from'))->format('Y-m-d'))

->orWhere('created_at','在控制器中)应使用请求获取如下输入文本值:

public function login_history_search(Request $request)
{
    $daterange = 
    $histories = DB::table('loginhistories')
    ->where('last_login_at', '>=', $request->input('daterange_from'))
    ->orwhere('last_logout_at', '<=', $request->input('daterange_to'))
    ->get();
    dd(request($histories));
    return view('profiles.login_histories', ['histories' => $histories]);
}
公共功能登录\u历史\u搜索(请求$Request)
{
$daterange=
$histories=DB::table('loginhistories')
->其中('last_login_at','>=',$request->input('daterange_from'))

->或者控制器中的where('last_logout_at','应使用请求获取如下输入文本值:

public function login_history_search(Request $request)
{
    $daterange = 
    $histories = DB::table('loginhistories')
    ->where('last_login_at', '>=', $request->input('daterange_from'))
    ->orwhere('last_logout_at', '<=', $request->input('daterange_to'))
    ->get();
    dd(request($histories));
    return view('profiles.login_histories', ['histories' => $histories]);
}
公共功能登录\u历史\u搜索(请求$Request)
{
$daterange=
$histories=DB::table('loginhistories')
->其中('last_login_at','>=',$request->input('daterange_from'))

->或者where('last_logout_at','最后,我通过下面的代码得到了正确的结果。:)谢谢@Maraboc!!

其核心思想是使用whereBetween查询生成器

public function login_history_search(Request $request) 
  { 
  $histories = DB::table('loginhistories') 
  ->whereBetween('last_login_at', array(
    (Carbon::parse($request->input('datepicker_from'))->format('Y-m-d')),
    (Carbon::parse($request->input('datepicker_to'))->format('Y-m-d'))
    )
   ) 
  ->get();
  return view('profiles.login_histories', ['histories' => $histories]); 
  }

最后,我通过下面的代码得到了正确的结果。:)谢谢@Maraboc!!

其核心思想是使用whereBetween查询生成器

public function login_history_search(Request $request) 
  { 
  $histories = DB::table('loginhistories') 
  ->whereBetween('last_login_at', array(
    (Carbon::parse($request->input('datepicker_from'))->format('Y-m-d')),
    (Carbon::parse($request->input('datepicker_to'))->format('Y-m-d'))
    )
   ) 
  ->get();
  return view('profiles.login_histories', ['histories' => $histories]); 
  }

你好;){Form::open(array('class'=>'Form'))!!{{Form::input('text','daterange','01/10/2017-01/11/2017',['id'=>'datepicker'])}{Form::submit('Search',['class'=>'btn btn success'])如何使用提交按钮获取代码中的搜索结果?非常感谢。让控制器获取输入的日期范围值有点困难。:(
dd(request('daterange'))的返回值是多少?)
在控制器中?因为我从来没有使用过这个日期选择器:pI找到了这个有用的链接,但是我如何才能调整到集合的Laravel中。嗨;{Form::open(array('class'=>'Form'))!!}{{Form::input('text','daterange','01/10/2017-01/11/2017',['id'=>'datepicker'])}{Form submit Form submit('Search',['class'=>'btn btn success'])!!}如何使用提交按钮获取代码中的搜索结果?非常感谢。让控制器获取输入的日期范围值有点困难。:(
dd(request('daterange')的返回值是多少);
在控制器中?因为我从来没有使用过这个日期选择器:pI找到了这个有用的链接,但是我如何才能调整到集合的Laravel中。你能添加路由吗?好的,只需添加要查看的路由,因为MethodNotAllowedHttpException与它们相关:)@Maraboc,我认为我的方法是错误的。DateRange选择器似乎无法在我的数据库中查询。原因是存储在DataRange和服务器中的日期值彼此不同。是否正确?如果正确,那么我只是尝试调整“日期选择器”:)我不这么认为,因为问题可能是,在路由中,您希望以POST请求的形式出现GET请求bau,因此在路由文件中进行更改,然后在此处添加一个参数
login\u history\u search(request$request)
然后删除
if(!isset($\u GET['daterange')){
then test;)@Maraboc,好的,那么我必须修改正确的DB:raw()query.:)thx!!你能添加路由吗?好的,请添加路由查看,因为MethodNotAllowedHttpException与它们相关:)@Maraboc,我认为我的方法是错误的。DateRange选择器似乎无法在我的数据库中查询。原因是DataRange和服务器中存储的日期值彼此不同r、 是否正确?如果正确,那么我只是尝试调整“日期选择器”:)我不这么认为,因为问题很可能是在路由中,您希望一个GET请求bau以POST请求的形式出现,所以在路由文件中进行更改,然后在此处添加一个参数
login\u history\u search(request$request)
然后删除
if(!isset($\u GET['daterange']){
then test;)@Maraboc,好的,那么我必须修改正确的DB:raw()查询。:)thx!!