Oct 30, 2020
0
Level 4
Help with querying product filter
I want to sort listed products in the category selected, i need help with the controller querying.
My Blade File
@extends('layouts.cat5')
@section('content')
@include('frontEnd.ourJs')
<div class="contact-container" style="align-items: flex-start;">
<div class="form-container lcontact-form" style="width: 100%;">
<h3 style="margin-bottom: revert; margin-top:12px;">Filter Category</h3>
<div style="display: inline-block; margin-top:12px; text-align: center;">
<input type="text" id="catID" value="{{$catByUser}}" hidden/>
<input type="number" id="minpriceID" min="0" class="form-control" style="margin: inherit;" placeholder="Min Price">
<input type="number" id="maxpriceID" min="0" class="form-control" style="margin: inherit;" placeholder="Max Price">
<input type="text" id="search" class="form-control" style="margin: inherit;" placeholder="search product by name">
<div style="margin-top:inherit;">
<button class="login-btn form-control" id="findBtn" style="margin: inherit; border-left: inset;"> <span class="fas fa-filter"></span> Filter</button>
</div>
</div>
</div>
<div class="gender-clothing">
<div class="title-row">
<div class="main-title">
<h3 style="font-size: xx-large;">{{$catname->name}} Category</h3>
</div>
</div>
<div class="cloth-row">
@if(count($data)=="0")
<h1 align="center" style="margin-top:20px">
No products found under
<b style="color:red">{{$catByUser}} </b>
Category
</h1>
@elseif (count($data)!="0")
@foreach($data as $p)
<div class="cloth" id="productData">
<div class="card">
<img src="/products/large/{{$p->image}}" alt="{{$p->image}}" style="width:100%">
<h1 style="margin-top: revert;">{{$p->p_name}}</h1>
<br>
<p class="price" style="color:#0d6cb3;">NGN {{$p->price}}</p>
<br>
<p><a href="/product-detail/{{$p->id}}/{{$p->slug}}"><button>Explore</button></a></p>
</div>
</div>
@endforeach
@endif
</div>
</div>
</div>
<!-- <div class="container">
<div class="row">
<div class="col-sm-3">
</div>
<div class="col-sm-9 padding-right">
@if(count($data)!="0")
<h1 class="text-center">{{$catByUser}} </h1>
<div class="row">
<div class="">
<select id="catID">
<option value="{{$catByUser}}">{{$catname->name}}</option>
</select>
</div>
<div class="">
<select id="priceID">
<option value="">Select Price Range</option>
<option value="100">0-100</option>
<option value="100-300">100-300</option>
<option value="300-500">300-500</option>
<option value="500-1000">500-1000</option>
</select>
<input type="number" id="priceID">
</div>
<div class="col-sm-6 hidden-xs">
<div class="row">
<div class="col-sm-4 pull-right">
<button id="findBtn" class="btn btn-success">Find</button>
</div>
<div class="styleNm">16 style(s)</div>
</div>
</div>
@endif
</div>
<div class="row top25">
@if(count($data)=="0")
<div class="col-md-12" align="center">
<h1 align="center" style="margin:20px">
No products found under
<b style="color:red">{{$catByUser}} </b>
Category </h1>
</div>
@else
<div id="productData">
@foreach($data as $p)
<div class="col-xs-6 col-sm-4" >
<div class="itemBox">
<div class="prod">
<img
src="/products/large/{{$p->image}}" alt="/products/large/{{$p->image}}"
width="400px" height="360px" /></div>
<label>{{$p->p_name}}</label>
<span class="hidden-xs">Code: {{$p->p_code}}
<br>
{{$p->pro_info}}</span>
<div class="addcart">
<div class="price">NGN {{$p->price}}</div>
<div class="cartIco hidden-xs"><a href="{{url('/cart/add')}}/{{$p->id}}"></a></div>
</div>
</div>
</div>
@endforeach
</div>
@endif
</div>
</div>
</div> -->
@endsection
ourJs
<script>
$(document).ready(function(){
$("#findBtn").click(function(){
var cat = $("#catID").val();
var minprice = $('#minpriceID').val();
var maxprice = $('#maxpriceID').val();
var search = $('#search').val();
$.ajax({
type: 'get',
dataType: 'html',
url: '{{url('/productsCat')}}',
data: 'cat_id=' + cat + 'min_price=' + minprice + 'max_price' + maxprice + 'search' + search,
success:function(response){
console.log(response);
$("#productData").html(response);
}
});
});
});
</script>
Web Route
Route::get('/selected-category/{id}/{slug}', 'SelectedCategoryController@show')->middleware('auth');
Route::get('selected-category/{id}/{slug}','SelectedCategoryController@show');
Route::get('productsCat','SelectedCategoryController@productsCat');
Controller
public function show($id, $slug, Request $request)
{
$cat = $id;
// dd($cat);
$catByUser = $cat;
$catname = ProductCategory::find($slug);
$subcategory = SubCategory::with(['productCategory'])->orderBy('name')->get();
$data = Product::where('categories_id', $cat)->get();
// dd($catname);
$cart = User::findorfail(auth()->user()->id)->cart;
$user = auth()->user()->id;
$messages = User::findorfail($user)->latestmessaging->count();
// dd($category);
return view('frontEnd.product-category', compact('data', 'catname', 'catByUser', 'subcategory', 'cart', 'messages'));
}
public function productsCat(Request $request){
$cat_id = $request->cat_id;
// dd(count($request->price));
$pricemax= $request->max_price;
$pricemin= $request->min_price;
$search= $request->search;
}
I need help with the querying...
Please or to participate in this conversation.