Javascript 如何在PHP Laravel中创建具有过滤日期差分功能的选择按钮?

Javascript 如何在PHP Laravel中创建具有过滤日期差分功能的选择按钮?,javascript,php,jquery,html,laravel,Javascript,Php,Jquery,Html,Laravel,目前,我想创建一个具有不同功能的选择按钮。该按钮由两个选项组成,即行程日期和发布日期。因此,当用户单击旅行日期时,它将过滤旅行日期函数,当用户单击发布日期时,它将过滤发布日期函数。我已经在view.blade.php中创建了选择按钮。以及过滤日期的功能。我试图将正确的选择连接到正确的功能,但似乎没有成功。我实际上如何传递选择的值?因此,当函数获取值时,它们将过滤日期 HTML <select class="form-control" name="insurance_id" onchang

目前,我想创建一个具有不同功能的选择按钮。该按钮由两个选项组成,即行程日期和发布日期。因此,当用户单击旅行日期时,它将过滤旅行日期函数,当用户单击发布日期时,它将过滤发布日期函数。我已经在view.blade.php中创建了选择按钮。以及过滤日期的功能。我试图将正确的选择连接到正确的功能,但似乎没有成功。我实际上如何传递选择的值?因此,当函数获取值时,它们将过滤日期

HTML

<select class="form-control" name="insurance_id" onchange="alert(this.options[this.selectedIndex].value);">
     <option value="Travelled" id="myInput">Travel Date</option>
     <option value="Issued" id="myButton">Issued Date</option>
</select>

我认为这段代码可能会被编辑以实现您这么长时间以来的目标,请记住我的评论,但基本思想是使用元素“select”上的值(称为“insurance_id”),根据该值确定要执行的操作:

    $insurance_id = $request->insurance_id; //HERE is where we determine if we are going to use travelled or Issued, since the "name" attribute of the "select" element is "insurance_id"
    $exported = $request->exported;

    if($insurance_id == "Travelled") { //now our conditional should reflect this
    //function travelled date
    $travelleddate = InsuranceEnrollment::where('status', '=', 2)
        ->where("insurance_id", $insurance_id)
        ->whereBetween('depart_date', [$from, $to])
        ->orderBy('depart_date', 'DESC')
        ->paginate(10);
    } 
   elseif($insurance_id == "Issued") { //and this one too, unless a simple else may do here.
    //function issued date
    $issueddate = InsuranceEnrollment::where('status', '=', 2)
        ->where("insurance_id", $insurance_id)
        ->whereBetween('created_at', [$from, $to])
        ->orderBy('created_at', 'DESC')
        ->paginate(10);
    }

这段代码可以正常工作吗?为什么要对
字符串
未定义常量
使用
运算符?它根本不起作用。我应该在控制器上请求视图的id吗@BanujanBalendrakumar
if(请求>“旅行”)
解释一下这个if($request->myInput),我这样想。意味着当用户单击id=myInput的选择时,它将进入if语句
    $insurance_id = $request->insurance_id; //HERE is where we determine if we are going to use travelled or Issued, since the "name" attribute of the "select" element is "insurance_id"
    $exported = $request->exported;

    if($insurance_id == "Travelled") { //now our conditional should reflect this
    //function travelled date
    $travelleddate = InsuranceEnrollment::where('status', '=', 2)
        ->where("insurance_id", $insurance_id)
        ->whereBetween('depart_date', [$from, $to])
        ->orderBy('depart_date', 'DESC')
        ->paginate(10);
    } 
   elseif($insurance_id == "Issued") { //and this one too, unless a simple else may do here.
    //function issued date
    $issueddate = InsuranceEnrollment::where('status', '=', 2)
        ->where("insurance_id", $insurance_id)
        ->whereBetween('created_at', [$from, $to])
        ->orderBy('created_at', 'DESC')
        ->paginate(10);
    }