フィルタを使用して製品を表示します。 正しくフィルタリングされた結果が得られました。しかし、私は次のフィルタでフィルタ結果を保持することはできません。 つまり、3つのフィルタを使用しています。 作成日時フィルタ 価格 - フィルタ 売り手 - フィルタチェックボックスをオンにし、フィルタを使用した後にオプションを選択します。
すべて動作します。
しかし、私は次の次のフィルタリング結果でそれを作ることはできません。また、チェックされる値をチェックしたり、選択された値を選択することはできません。どうしたらいいですか?私は下記の私のコード:
はコントローラー:
$category_id = Category::where('name', $main)->value('id');
if($category_id == "")
{
$all_categories_id = Category::pluck('id');
}
else
{
$all_categories_id = Category::where('parent_id', $category_id)->pluck('id');
$all_categories_id->push($category_id);
}
$product_id = Product::where('name', 'like','%'.$request->name.'%')->pluck('id');
$id = ProductCategory::whereIn('product_id', $product_id)->whereIn('category_id', $all_categories_id)->pluck('id');
$product_id = Product::whereIn('id', $id)->pluck('id');
$seller = Product::whereIn('id', $id)->pluck('seller_id');
$seller_name = User::whereIn('id', $seller)->get();
$products = Product::where(function($query) use ($product_id){
$min_price = Input::has('min_price') ? Input::get('min_price') : null;
$max_price = Input::has('max_price') ? Input::get('max_price') : null;
$seller = Input::has('seller') ? Input::get('seller') : [];
if(isset($min_price) && isset($max_price)){
$query->whereBetween('price_per_unit', [$min_price, $max_price])
->whereIn('id', $product_id);
}
if(isset($days)){
foreach($days as $key => $day){
$end = Carbon::now();
$get_required_date = Carbon::now()->subDays($day);
$products = Product::where('created_at', '>', $get_required_date)->pluck('id');
$query->whereIn('id', $products)->whereBetween('price_per_unit', [$min_price, $max_price]);
}
}
if(isset($seller)){
foreach($seller as $key => $sell){
$query->whereIn('id', $product_id)
->where('seller_id', $sell);
}
}
$query->whereIn('id', $product_id);
})->get();
}
//Categories Name in Sidebar
$category = ProductCategory::whereIn('product_id', $id)->pluck('parent_id');
$category_name = Category::whereIn('id', $category)->pluck('name');
//Categories Name in dropdown
$main_categories = Category::where('parent_id', '0')->pluck('name');
//Profile Image Mapping
$user = Auth::user();
$directory = 'uploads/users/images/'.$user->id;
$main_categories = Category::where('parent_id', '0')->pluck('name');
if (is_dir($directory)) {
$files = scandir ($directory);
$img_file = $directory.'/'.$files[2];
$user['front_img'] = $img_file;
}
$profile = $user['front_img'];
//Product Image Mapping
$products->map(function ($product) {
$directory = 'uploads/products/images/'.$product->id;
$brand = Brand::select('name')->where('id', '=', $product->brand)->pluck('name');
$brand_name = $brand->first(function($value, $key) {
return $key == 'name';
});
if (is_dir($directory)) {
$files = scandir ($directory);
$img_file = $directory.'/'.$files[2];
$product['front_img'] = $img_file;
$product['brand'] = $brand_name;
return $product;
}
return $product;
});
return view('pages/product', compact('main_categories','seller_name', 'profile', 'products', 'main', 'category_name'));
そして、私のブレードコード:
@extends('layouts.master')
@section('content')
<section class="bc-product">
<div class="container">
<div class="row" >
<div class="breadcrumb-width">
<div class="col-sm-6">
<ul class="bc-breadcrumb">
<li><a href="/">Home</a>
</li>
<li class="active category"><a href="#">{{$main}}</a>
</li>
</ul>
</div>
<div class="col-sm-6">
<div class="pull-right">
<ul class="bc-Produc-mlist">
<li>View:Sort :</li>
<li><a href="#"> Popular</a>
</li>
<li><a href="#"> NewDiscount </a>
</li>
<li><a href="#">Price: LowHigh</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="row" >
<div class="bc-Product-left hidden-sm hidden-xs">
<div class="bc-categories-left">
<span class="bc-expand-title">CATEGORIES</span>
<a class="bc-expand">
<div class="bc-expand-icon">[ - ]</div>
</a>
<div class="bc-detail-list">
<ul class="bc-categories-list">
@foreach($category_name as $m)
<li><a href="{{url('/product/'.$m)}}"><i class="fa fa-caret-right" aria-hidden="true"></i> {{$m}}</a></li>
@endforeach
</ul>
</div>
</div>
<form id="filterform">
<div class="bc-categories-left">
<div class="bc-product-mtb">
<span class="bc-expand-title">New Arrival</span>
<a class="bc-expand">
<div class="bc-expand-icon">[ - ]</div>
</a>
<div class="bc-detail-list">
<div class="checkbox checkbox-select">
<input id="7" name="days[]" value="7" type="checkbox"/>
<label for="7"> Last 07 days </label>
</div>
<div class="checkbox checkbox-select">
<input value="15" name="days[]" id="15" type="checkbox"/>
<label for="15">Last 15 days </label>
</div>
<div class="checkbox checkbox-select">
<input id="30" name="days[]" value="30" type="checkbox"/>
<label for="30">Last 30 days </label>
</div>
<div class="checkbox checkbox-select">
<input id="45" name="days[]" value="45" type="checkbox"/>
<label for="45"> Last 45 days </label>
</div>
</div>
</div>
</div>
<div class="bc-categories-left">
<div class="bc-product-mtb">
<span class="bc-expand-title">Price</span>
<a class="bc-expand">
<div class="bc-expand-icon">[ - ]</div>
</a>
<div class="bc-detail-list">
<div class="bc-range-bar">
<div class="bc-range-handle-left"></div>
<div class="bc-range-handle-right"></div>
</div>
<!--<input id="range" type="range" min="20" max="200"/>-->
<div class="form-group bc-form-pric-sm">
<select name="min_price" class="bc-select">
<option value="0">Min</option>
<option value="200" >$200</option>
<option value="500" >$500</option>
</select>
</div>
<div class="form-group bc-input-group">
<select name="max_price" class="bc-select">
<option value="1000000000000000">Max</option>
<option value="2000" >$2000</option>
<option value="5000" >$5000</option>
</select>
</div>
</div>
</div>
</div>
<div class="bc-categories-left">
<div class="bc-product-mtb">
<?php $seller = Input::has('seller') ? Input::get('seller') : []; ?>
<span class="bc-expand-title">Seller</span>
<a class="bc-expand">
<div class="bc-expand-icon">[ - ]</div>
</a>
<div class="bc-detail-list">
<?php $seller = Input::has('seller') ? Input::get('seller') : []; ?>
@foreach($seller_name as $seller)
<div class="checkbox checkbox-select">
<input id="{{$seller->id}}" name="seller[]" type="checkbox" value="{{$seller->id}}">
<label for="{{$seller->id}}"> {{$seller->name}} </label>
</div>
@endforeach
</div>
</div>
</div>
</div>
<button class="active" style="display: none;">ok</button>
<div class="bc-Product-right">
@foreach($products as $product)
<div class="bc-product-col">
<div class="bc-product-list">
<div class="bc-product-listimg">
<img src="{{ asset($product->front_img) }}" alt="Women">
</div>
<div class="bc-actions">
<a class=" bc-buy-line bc-view" href="#">View</a>
<a class="bc-buy" href="/buy-now">Buy</a>
</div>
<span class="bc-brand-name">{{$product->name}}</span>
<span class="bc-price">{{$product->price_per_unit}}</span>
</div>
</div>
@endforeach
</form>
<div class="text-right">
<div class="page-nation">
<ul class="pagination pagination-large">
<li class="disabled"><span>Prev</span></li>
<li class="active"><span>1</span></li>
<li><a href="#">2</a>
</li>
<li><a href="#">3</a>
</li>
<li><a href="#">4</a>
</li>
<li class="disabled"><span>...</span></li>
<li>
<li><a rel="next" href="#">Next</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</section>
<script>
$("input[name='seller[]']").click(function() {
$("button.active").trigger("click");
});
$("input[name='days[]']").click(function() {
$("button.active").trigger("click");
});
$("select[name='max_price'").change(function() {
$("button.active").trigger("click");
});
// $("#range").change(function(){
// var val = $('#range').val();
// console.log(val);
// });
</script>
@endsection
はどのようにそれを行うには?私がしたとしても、次のフィルターのためにそれを保持することができますか? – Kayal
どのアプローチを使いたいですか? 'ajax()'または 'form submit'ですか? 'ajax()'を使うことをお勧めします。 –
フォーム提出のみ。アヤックスでは難しいと感じているから – Kayal