0

I am fetching data from DB and try to filter those data. But not using selectBox trying to use ul > li Already setup the controller.

public function search(Request $request)
    {
        $q = $request->q;
        $sortbyprice = $request->sortbyprice;
        $region = $request->region;

        $paginationData = [
            'q' => $q
        ];

        $estates = \DB::table('allestates')
            ->where('lat', '!=', '')
            ->where('lng', '!=', '')
            ->where('price', '!=', '')
            ->where(function($query) use ($q) {
                $query->where("building_name", "LIKE", "%" . $q . "%")
                    ->orWhere("address", "LIKE", "%" . $q . "%")
                    ->orWhere("company_name", "LIKE", "%" . $q . "%")
                    ->orWhere("region", "LIKE", "%" . $q . "%");
            })
            ->when($sortbyprice, function($query, $order) use ($paginationData) {
                if(!in_array($order, ['asc','desc'])) {
                    $order = 'asc';
                }

                $paginationData['sortbyprice'] = $order;

                return $query->orderBy('price', $order);

            }, function($query) {
                return $query->orderBy('price');
            })
            ->when($region, function($query, $regionId) use ($paginationData) {
                $paginationData['region'] = $regionId;
                return $query->where('region', $regionId);
            })
            ->paginate(100);

        $paginationData = array_filter($paginationData);

        return view("home", compact('estates', 'q','paginationData'));
    }

I made a dropdown menu in the blade. But I am not very sure how to pass the values into menu. For example, when click I click the Price it automaticly filter it. Or when I click the Paris it fetch Paris from DB.

ul
{
    font-family: Arial, Verdana;
    font-size: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

ul li
{
    display: block;
    position: relative;
    float: left;
}

li ul
{
    display: none;
}

ul li a 
{
    display: block;
    text-decoration: none;
    color: #ffffff;
    border-top: 1px solid #ffffff;
    padding: 5px 15px 5px 15px;
    background: #2C5463;
    margin-left: 1px;
    white-space: nowrap;
}

ul li a:hover 
{
    background: #617F8A;
}
li:hover ul 
{
    display: block;
    position: absolute;
}

li:hover li
{
    float: none;
    font-size: 11px;
}

li:hover a 
{
    background: #617F8A;
}

li:hover li a:hover 
{
    background: #95A9B1;
}
<ul id="menu">
      <li><a href="">Sort Cheapest</a></li>
      <li><a href="">City</a>
        <ul>
        <li><a href="">Paris</a></li>
        <li><a href="">Amsterdam</a></li>
        <li><a href="">New York</a></li>
        </ul>
      </li>
</ul>

How can I pass "sortbyprice" and "region" or values like "paris" etc into menu...

2 Answers2

0

Maybe something like this <li><a href="/search?region=amsterdam">Amsterdam</a></li>

empy26
  • 81
  • 5
0

Please use this function to get the clicked data:-

$(function(){
    $("#menu li ul li a").click(function(){
        var item = $(this).text();
        var searchfrom  = $(this).parent().parent().parent().text();
        window.location = APP_URL+"/search?q="+searchfrom+"="+item;

   });
});

How to Display Selected Item in Bootstrap Button Dropdown Title

phpdroid
  • 1,642
  • 1
  • 18
  • 36