I am building search filtering for my site and I am trying to use livewire to build the search component. The search component has a few filters and one of them is a categories dropdown with a subcategories dropdown below it. When a top-level category is selected it should update the subcategories dropdown with the sub-categories of the top-level category. This should happen dynamically without updating the rest of the component, but the actual search results should only be returned when the apply filter button is pressed.
But the subcategories dropdown is not being updated even though if I dd on $this->subcategories I can see the variable has actually been updated. What am I doing wrong here:
<div class="col-xs-12 col-sm-5 col-md-4 col-lg-3">
<aside id="tg-sidebar" class="tg-sidebar">
<form wire:submit.prevent="submitSearch" class="tg-formtheme tg-formnerrowsearch">
<div class="tg-sidebartitle"><h2>Narrow Your Search:</h2></div>
<fieldset>
<div id="tg-narrowsearchcollapse" class="tg-themecollapse tg-narrowsearchcollapse" wire:ignore>
<div class="tg-collapsetitle">
<i class="fa fa-rotate-left"></i>
<span class="fa fa-angle-down">By Title/Keyword</span>
</div>
<div class="tg-themecollapsecontent">
<div class="form-group tg-inputwithicon">
<i class="icon-magnifier"></i>
<input wire:model.defer="keyword" id="keyword" type="search" name="keyword" class="form-control" placeholder="Search Title/Keyword">
</div>
</div>
<div class="tg-collapsetitle">
<i class="fa fa-rotate-left"></i>
<span class="fa fa-angle-down">By Category</span>
</div>
<div class="tg-themecollapsecontent">
<div class="form-group">
<div class="tg-select">
<select wire:model="category" id="category" name="category">
<option disabled>Select Category</option>
#foreach ($categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<div class="tg-selectgroup">
<select wire:model.defer="subcategory" id="subcategory" name="subcategory">
<option disabled>Select Subcategory</option>
#if(count($subcategories) > 0)
#foreach ($subcategories as $subcategory)
<option value="{{$subcategory->id}}">{{$subcategory->name}}</option>
#endforeach
#endif
</select>
</div>
</div>
</div>
<div class="tg-collapsetitle">
<i class="fa fa-rotate-left"></i>
<span class="fa fa-angle-down">By Location</span>
</div>
<div class="tg-themecollapsecontent">
<div class="form-group tg-inputwithicon">
<i class="fa fa-crosshairs"></i>
<input wire:model.defer="city" id="city" type="text" name="city" class="form-control" placeholder="Town/City">
</div>
<div class="form-group tg-inputwithicon">
<i class="fa fa-map-marker"></i>
<input wire:model.defer="postcode"id="postcode" type="text" name="postcode" class="form-control" placeholder="Postcode">
</div>
<div class="form-group">
<div class="tg-select">
<select wire:model.defer="distance" id="radius" name="radius">
<option>Distance</option>
<option value="1">Within 1 mile</option>
<option value="5">Within 5 miles</option>
<option value="10">Within 10 miles</option>
<option value="15">Within 15 miles</option>
<option value="20">Within 20 miles</option>
<option value="25">Within 25 miles</option>
<option value="30">Within 30 miles</option>
<option value="35">Within 35 miles</option>
<option value="40">Within 40 miles</option>
<option value="45">Within 45 miles</option>
<option value="50">Within 50 miles</option>
<option value="55">Within 55 miles</option>
<option value="60">Within 60 miles</option>
<option value="70">Within 70 miles</option>
<option value="80">Within 80 miles</option>
<option value="90">Within 90 miles</option>
<option value="100">Within 100 miles</option>
<option value="150">Within 150 miles</option>
<option value="200">Within 200 miles</option>
<option value="1200">Nationwide</option>
</select>
</div>
</div>
</div>
<div class="tg-collapsetitle">
<i class="fa fa-rotate-left"></i>
<span class="fa fa-angle-down">By Ads Type</span>
</div>
<div class="tg-themecollapsecontent">
<div class="tg-checkboxgroup">
<span class="tg-checkbox">
<input wire:model.defer="featured" type="checkbox" id="tg-featuredads" name="featured" value="1">
<label for="tg-featuredads">
<span>Featured Ads</span>
<span>987327</span>
</label>
</span>
<span class="tg-checkbox">
<input wire:model.defer="urgent" type="checkbox" id="tg-urgentads" name="urgent" value="1">
<label for="tg-urgentads">
<span>Urgent Ads</span>
<span>48952413</span>
</label>
</span>
<span class="tg-checkbox">
<input wire:model.defer="auction" type="checkbox" id="tg-auctionads" name="auction" value="1">
<label for="tg-auctionads">
<span>Auctions</span>
<span>48952413</span>
</label>
</span>
<span class="tg-checkbox">
<input wire:model.defer="will_post" type="checkbox" id="tg-postageads" name="will_post" value="1">
<label for="tg-postageads">
<span>Willing to Post</span>
<span>48952413</span>
</label>
</span>
</div>
</div>
</div>
<button type="submit" class="tg-btn">apply filter</button>
</fieldset>
</form>
</aside>
</div>
<div class="col-xs-12 col-sm-7 col-md-8 col-lg-9">
<div id="tg-content" class="tg-content">
<div class="tg-contenthead">
<div class="tg-sortandview">
<div class="tg-sortby">
<strong>Sort by:</strong>
<div class="tg-select">
<select>
<option value="Most Recent">Most Recent</option>
<option value="Most Recent">Most Recent</option>
<option value="Most Recent">Most Recent</option>
</select>
</div>
</div>
<div class="tg-views">
<strong>View As Grid</strong>
<ul>
<li class="tg-active"><a href="javascript:void(0);"><i
class="fa fa-th-large"></i></a></li>
<li><i class="fa fa-reorder"></i></li>
</ul>
</div>
</div>
<div class="tg-applyedfilters">
<ul>
<li class="alert alert-dismissable fade in">
×
<span>Manchester</span>
</li>
<li class="alert alert-dismissable fade in">
×
<span>0 - 0</span>
</li>
<li class="alert alert-dismissable fade in">
×
<span>Brand New</span>
</li>
<li class="alert alert-dismissable fade in">
×
<span>Featured Ads</span>
</li>
<li class="alert alert-dismissable fade in">
×
<span>Area Unit: Sq. ft.</span>
</li>
<li class="alert alert-dismissable fade in">
×
<span>Sq. ft. 2500 - Sq. ft.5000</span>
</li>
<li class="alert alert-dismissable fade in">
×
<span>Rooms: 04</span>
</li>
<li class="alert alert-dismissable fade in">
×
<span>2014 - 2016</span>
</li>
<li class="alert alert-dismissable fade in">
×
<span>1500 - 3000</span>
</li>
<li><a class="tg-btncleall" href="javascript:void(0);">Clear All</a></li>
</ul>
</div>
</div>
<div class="tg-ads">
<div class="row">
#if(empty($results))
<div class="alert alert-warning">
<strong>Sorry!</strong> No Adverts Found.
</div>
#else
#foreach($results as $result)
<div class="col-xs-6 col-sm-12 col-md-6 col-lg-4 tg-verticaltop">
<div class="tg-ad tg-verifiedad">
<figure>
<span class="tg-themetag tg-featuretag">featured</span>
<a href="{{route('listing.view', $result)}}">
#if(isset($result->images->where('order', '=', 1)->first()->name))
<img src="{{asset ('storage/ad_images/thumbnails/'.$result->images->where('order', '=', 1)->first()->name)}}" title="{{$result->images->where('order', '=', 1)->first()->title}}" alt="{{$result->images->where('order', '=', 1)->first()->alt}}">
#else
#endif
</a>
<span class="tg-photocount">See {{$result->images->count()}} Photos</span>
</figure>
<div class="tg-adcontent">
<ul class="tg-productcagegories">
<li>{{$result->categories->last()->name}}</li>
</ul>
<div class="tg-adtitle">
<h3>{{$result->title}}</h3>
</div>
<time datetime="2017-06-06">Last Updated: {{\Carbon\Carbon::createFromTimeStamp(strtotime($result->updated_at))->diffForHumans()}}</time>
<div class="tg-adprice"><h4>£{{$result->price}}</h4></div>
<address>
#foreach (json_decode($result->user->addresses->where('id', '=', $result->user_address_id)) as $address)
{{$address->city.' '.$address->post_code}}
#endforeach
</address>
<div class="tg-phonelike">
<a class="tg-btnphone" href="javascript:void(0);">
<i class="icon-phone-handset"></i>
<span data-toggle="tooltip" data-placement="top" title="Show Phone No." data-last="{{$result->user->contacts->where('id', '=', $result->user_contact_id)->first()->mobile}}"><em>Show Phone No.</em></span>
</a>
<span class="tg-like tg-liked"><i class="fa fa-heart"></i></span>
</div>
</div>
</div>
</div>
#endforeach
#endif
</div>
</div>
{{-- <nav class="tg-pagination">
namespace App\Http\Livewire;
use Livewire\Component;
use App\Category;
use App\User;
use App\Advert;
class Listings extends Component
{
public $keyword;
public $categories = [];
public $category;
public $subcategories = [];
public $subcategory;
public $city;
public $postcode;
public $distance;
public $featured;
public $urgent;
public $auction;
public $will_post;
public $results;
public $model;
public function mount($model, $paginate = '10')
{
$this->model = $model;
$this->paginate = $paginate;
$this->categories = Category::whereNull('parent_id')->get();
$this->subcategories = Category::with('children')->where('parent_id', $this->categories->first()->id)->get();
}
public function submitSearch()
{
$advert = new Advert();
if($this->featured){
$advert = $advert->where('mark_ad_featured', '1');
}
if($this->urgent){
$advert = $advert->where('mark_ad_urgent', '1');
}
if($this->auction){
$advert = $advert->where('is_auction', '1');
}
if($this->auction){
$advert = $advert->where('is_auction', '1');
}
if($this->will_post){
$advert = $advert->where('local_pickup', '0');
}
$advert = $advert->where('status', '1');
$advert->orderBy('updated_at', 'asc');
$this->results = $advert->get();
}
public function render()
{
if(!empty($this->category)) {
$this->subcategories = Category::where('parent_id', $this->category)->get();
}
//dd($this->subcategories);
return view('livewire.listings');
}
}
I have tried using the updated lifecycle hook for category property change but it still does not work:
public function updatedCategory($value)
{
if($value) {
$this->category = $value;
$this->subcategories = Category::where('parent_id', $this->category)->get();
}
}
could you change the wire:ignore in this line for wire:ignore.self or not use it if isn't necessary ??? i can't figure it out anything else in that code
<div id="tg-narrowsearchcollapse" class="tg-themecollapse tg-narrowsearchcollapse" wire:ignore.self>
Related
For my website I want to display search result (on a complete new page) using the parameters in the dropdown select input. I have 4 dropdowns and I tried multiple different ways to make it work. But it doesn't seem to work!
Below is my CodeIgniter 4 code
Home Controller
The home controller file which gathers data from 4 dropdown inputs the data is fetched as an array. The array is then executed through the getSearch method located in the home model.
public function search_residential() {
$data['getfooter'] = $this->homeModel->getFooterInfo();
$params = array(
'category' => $this->request->getVar('category'),
'area' => $this->request->getVar('area'),
'bedrooms' => $this->request->getVar('bedrooms'),
'washrooms' =>$this->request->getVar('washrooms'),
);
$data['search'] = $this->homeModel->getSearch($params);
return view('search', $data);
}
Home Model
The home model contains the query of search.
//Searching data
public function getSearch($params) {
$category = $params['category'];
$area = $params['area'];
$bedrooms = $params['bedrooms'];
$washrooms = $params['washrooms'];
$builder= $this->db->table('tblresidential');
$builder->select('*');
$builder->where('1 = 1');
if ($category != '') {
$builder->where('category', $category);
}
if ($area != '') {
$builder->where('area', $area);
}
if ($bedrooms != '') {
$builder->where('bedrooms', $bedrooms);
}
if ($washrooms != '') {
$builder->where('washrooms', $washrooms);
}
$result = $builder->get();
return $result;
}
HTML Code
The HTML code that is used for execution
<div class="search__area-inner">
<?= form_open('/home/search_residential'); ?>
<div class="row">
<div class="col-6 col-lg-3 col-md-3">
<div class="form-group">
<select name="category" class="wide select_option">
<option data-display="Property Type">Property Type</option>
<option value="Property on sale">Property on Sale</option>
<option value="Property on rent">Property on Rent</option>
</select>
</div>
</div>
<div class="col-6 col-lg-3 col-md-3">
<div class="form-group">
<select name="area" class="wide select_option">
<option data-display="Select Area">Select Area</option>
<option value="2000">2000</option>
<option value="1800">1800</option>
<option value="1500">1500</option>
<option value="1200">1200</option>
<option value="900">900</option>
<option value="600">600</option>
<option value="300">300</option>
<option value="100">100</option>
</select>
</div>
</div>
<div class="col-6 col-lg-3 col-md-3">
<div class="form-group">
<select name="bedrooms" class="wide select_option">
<option data-display="Select Bedrooms">Select Bedrooms</option>
<option value="1 bedroom">1</option>
<option value="1.5 bedrooms">1.5</option>
<option value="2 bedrooms">2</option>
<option value="2.5 bedrooms">2.5</option>
<option value="3 bedrooms">3</option>
<option value="4 bedrooms">4</option>
<option value="5 bedrooms">5</option>
</select>
</div>
</div>
<div class="col-6 col-lg-3 col-md-3">
<div class="form-group">
<select name="washrooms" class="wide select_option">
<option data-display="Select Washrooms">Washrooms</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
<div class="col-12">
<div class="form-group">
<button class="btn btn-primary text-uppercase btn-block"> search
<i class="fa fa-search ml-1"></i>
</button>
</div>
</div>
</div>
<?= form_close(); ?>
</div>
Result View (the page on which result shows)
This is the page where result shows
<?php if(!empty($search)) : ?>
<section class="residential-property-list">
<div class="container">
<div class="row">
<?php foreach($search as $properties) : ?>
<div class="col-lg-12">
<div class="card__image card__box-v1">
<div class="row no-gutters">
<div class="col-md-4 col-lg-3 col-xl-4">
<div class="card__image__header h-250">
<a href="<?= base_url('/home/residential_property'); ?>/<?= $properties->id; ?>">
<img src="<?= $properties->imageone; ?>" alt="featured-image" class="img-fluid w100 img-transition">
<div class="info text-white"> for <?= $properties->category; ?></div>
</a>
</div>
</div>
<div class="col-md-4 col-lg-6 col-xl-5 my-auto">
<div class="card__image-body">
<h6 class="text-capitalize">
<?= $properties->project; ?>
</h6>
<ul class="list-inline card__content">
<li class="list-inline-item">
<span>
Bedrooms <br>
<i class="fa fa-inbox"></i> <?= $properties->bedrooms; ?>
</span>
</li>
<li class="list-inline-item">
<span>
Washrooms <br>
<i class="fa fa-map"></i> <?= $properties->washrooms; ?>
</span>
</li>
<li class="list-inline-item">
<span>
Property Facing <br>
<i class="fa fa-inbox"></i> <?= $properties->facing; ?>
</span>
</li>
<li class="list-inline-item">
<span>
Property area <br>
<i class="fa fa-map"></i> <?= $properties->area; ?>
</span>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</section>
<?php else: ?>
<br>
<br>
<div class="container"><h4 class="text-center">No Result Found Yet</h4></div>
<br>
<br>
<?php endif; ?>
The model's get(...) method returns false|ResultInterface.
To receive the actual result set,
Instead of:
(Home Model)
// ...
$result = $builder->get();
return $result;
// ...
Use this:
Result Arrays
// ...
return $builder->get()->getResult();
// ...
I need to edit the error that shows if a user enters an amount below minimum but I can't find the file to edit the pop-up error response that shows if the amount I less than the withdrawal limit.
Here is the code.
<div class="row">
<div class="col-md-9">
<div class="card">
<div class="card-header">
<h4 class="card-title">withdrawal -
<small class="category">Cash Out Fund.</small>
</h4>
</div>
<div class="card-content">
<div class="row">
<div class="col-md-2">
<ul class="nav nav-pills nav-pills-icons nav-pills-primary nav-stacked" role="tablist">
<li class="active">
<a href="#withdraw" role="tab" data-toggle="tab">
<i class="material-icons">redeem</i>Withdraw
</a>
</li>
</ul>
</div>
<div class="col-md-10">
<div class="tab-content">
<div class="tab-pane active" id="withdraw">
<div class="alert alert-info">
<span class="text-center">Please Read before you proceed. You need to know processing fee:</span><br> #php $id=0;#endphp #foreach($gateways as $gateway) #php $id++;#endphp
<span>{{$id}}. <b>#if($gateway->name){{$gateway->name}}#endif #if($gateway->local_name){{$gateway->local_name}}#endif</b> we would charge you <b>{{config('app.currency_symbol')}} {{$gateway->fixed}}</b> fixed + <b>{{$gateway->percent}}%</b> to Withdraw.</span> #endforeach
</div>
<form action="{{route('userWithdraw.post')}}" method="post">
{{ csrf_field() }} #if(count($errors) > 0)
<div class="alert alert-danger alert-with-icon" data-notify="container">
<i class="material-icons" data-notify="icon">notifications</i>
<span data-notify="message">
#foreach($errors->all() as $error)
<li><strong> {{$error}} </strong></li>
#endforeach
</span>
</div>
<br> #endif
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="form-group label-floating">
<select class="selectpicker" name="gateway" data-style="btn btn-warning btn-round" title="Select Withdraw Gateway" data-size="7">
#if($gate->status == 1)
<option value="1000">{{$gate->name}}</option>
#endif #foreach($gateways as $gateway)
<option value="{{$gateway->id}}">{{$gateway->name}}</option>
#endforeach
</select>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="form-group label-floating">
<label class="control-label" for="account">Your PayPal</label>
<input id="account" name="account" type="text" class="form-control">
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="form-group label-floating">
<label class="control-label" for="amount">Withdraw Amount</label>
<input id="amount" name="amount" type="text" class="form-control">
</div>
</div>
</div>
I need to edit all error response that pops up in the file and any other error response on the entire website.
Here is the update of my question:
I am having a filter tab from the database but and doing a loop to show the filters tab.
PROBLEM
But the problem is when we click on tabs it should show a dropdown from where I can choose what we want to filter. but its only showing first filter and other are not working.
EDIT
my view file
<form id="tabForms" action="{{route('o')}}" method="GET">
<div class="col-xs-12 col-sm-8 col-md-6 filter-bootstrap" style="padding:0px;margin-bottom:20px;">
<div class="input-group input-group-lg">
<div class="input-group-btn">
<button type="button" class="btn btn-warning dropdown-toggle"
data-toggle="dropdown" aria-expanded="false"
style="background:#FFF;color:#575962;border:solid 1px #e7ecf1;box-shadow: none;font-weight: 300;
font-size: 15px;text-transform: capitalize;padding: 5px 12px;height: 35px;border-radius:3px 0px 0px 3px;">Add Search Field
</button>
<ul class="dropdown-menu productFilter" id="filters">
<li id="Payment Status" onclick="productFilter(this.id)" >Payment Status</li>
<li id="Shipping Status" onclick="productFilter(this.id)" >Shipping Status</li>
<li id="Order Total" onclick="productFilter(this.id)" >Order Total</li>
<li id="Item Weight" onclick="productFilter(this.id)" >Item Weight</li>
<li id="Shipping class Name" onclick="productFilter(this.id)" >Shipping class Name</li>
<li id="Shipping Country" onclick="productFilter(this.id)" >Shipping Country</li>
<li id="Refund Status" onclick="productFilter(this.id)" >Refund Status</li>
<li id="Shipping class Name" onclick="productFilter(this.id)" >Shipping class Name</li>
<li id="Warehouse Location" onclick="productFilter(this.id)" >Warehouse Location</li>
<li id="Shipment Status Date" onclick="productFilter(this.id)" >Shipment Status Date</li>
<li id="Payment status" onclick="productFilter(this.id)" >Payment status</li>
</ul>
<input type="hidden" class="form-control" name="productFilterType" value="" id="productFilterType"/>
</div>
<!-- /btn-group -->
<!--show text on input -->
<div class="filter-top">
#php
use App\Filter;
$userId = Auth::id();
$filters = Filter::where('user_id',$userId)->get();
foreach($filters as $getfilter)
{
$filter_name = $getfilter->filter_name;
$filter_id = $getfilter->id;
#endphp
<label id="inputTagFilterId" class=filter-id{{$filter_id}} style="color:#666;margin:7px;"> {{$filter_name}} <span class="close-tab"><a style="border-left: dotted 1px #666;color: #666;"> X </a></span></label>
#php }
#endphp
</div>
<div id="filterpop">
<div class='tb-dropdown tb-fieldfilter-popup tb-fieldfilter-selectfieldfiltereditor-popup tb-fieldfilter-selectfieldfiltereditor-popup-large' style='display: block; min-width: 261px; z-index: 1001; opacity: 1; left: 513.609px; top: 195.75px;' data-turbodropdown-popup='' data-positioned='bottomleft'>
<div class='tb-fieldfilter-popup-fields'>
<select class='tb-select tb-fieldfilter-selectfieldfiltereditor-operators' data-turbofieldfilter-selectfieldfiltereditor-operator-field=''>
<option value='equals'>Equals</option>
<option value='notEquals'>Not Equals</option>
<option value='in'>In List</option>
<option value='notIn'>Not In List</option>
</select>
<span class='tb-fieldfilter-popup-errors' data-turbofieldfilter-selectfieldfiltereditor-operator-errors=''></span>
<span class='tb-fieldfilter-selectfieldfiltereditor-values' data-turbofieldfilter-selectfieldfiltereditor-value-fields=''>
<div class='tb-fieldfilter-selectfieldfiltereditor-selector tb-inlineselect tb-inlineselect-multiple' data-turbofieldfilter-selectfieldfiltereditor-selector=''>
<div class='tb-inlineselect-messages' data-turboinlineselect-messages=''>
</div>
<div class='tb-inlineselect-searchbox tb-text-field tb-text-field-with-feedback tb-searchbox' data-turboinlineselect-searchbox=''>
<input type='text' class='tb-input' autocomplete='off' data-turbosearchbox-input='' placeholder='Search...'>
<i class='tb-text-field-feedback' data-turbosearchbox-state-indicator=''></i>
</div>
<div class='tb-inlineselect-selected-items' data-turboinlineselect-selected-items=''>
<div class='tb-inlineselect-selected-items-header' data-turboinlineselect-selected-items-header=''>
<span class='tb-inlineselect-selected-items-title' data-turboinlineselect-selected-items-title=''>Selected:</span>
</div>
<div class='tb-inlineselect-selected-items-viewport' data-turboinlineselect-selected-items-viewport='' style='height: 150px;'>
<div class='tb-inlineselect-selected-items-list' data-turboinlineselect-selected-items-list=''>
<div data-turbolistview-item-key='0' class='tb-listview-item'>
<div class='tb-inlineselect-item'>Unshipped</div>
</div>
</div>
</div>
</div>
<div class='tb-inlineselect-search-results' data-turboinlineselect-search-results='' style=''>
<div class='tb-inlineselect-search-results-header' data-turboinlineselect-search-results-header=''>
<span class='tb-inlineselect-search-results-title' data-turboinlineselect-search-results-title=''>Search Results:</span>
<span class='tb-inlineselect-select-all' data-turboinlineselect-select-all='' data-turboinlineselect-action='selectAll'>Select All</span>
<span class='tb-inlineselect-unselect-all' data-turboinlineselect-unselect-all='' data-turboinlineselect-action='unselectAll'>Clear</span>
</div>
<div class='tb-inlineselect-search-results-viewport' data-turboinlineselect-search-results-viewport='' style='height: 150px;'>
<div class='tb-inlineselect-search-results-list' data-turboinlineselect-search-results-list=''>
<div data-turbolistview-item-key='0' class='tb-listview-item tb-inlineselect-selected-item'>
<div class='tb-inlineselect-item'>Unshipped</div>
</div>
<div data-turbolistview-item-key='1' class='tb-listview-item'>
<div class='tb-inlineselect-item'>Shipped</div>
</div>
<div data-turbolistview-item-key='2' class='tb-listview-item'>
<div class='tb-inlineselect-item'>Partially Shipped</div>
</div>
<div data-turbolistview-item-key='4' class='tb-listview-item'>
<div class='tb-inlineselect-item'>Pending Shipment</div>
</div>
<div data-turbolistview-item-key='8' class='tb-listview-item'>
<div class='tb-inlineselect-item'>Canceled</div>
</div>
<div data-turbolistview-item-key='16' class='tb-listview-item'>
<div class='tb-inlineselect-item'>Third Party Managed</div>
</div>
</div>
<div class='tb-inlineselect-search-results-truncated' data-turboinlineselect-search-results-truncated=''>
</div>
</div>
</div>
</div>
<span class='tb-fieldfilter-popup-errors' data-turbofieldfilter-selectfieldfiltereditor-value-errors=''>
</span>
</span>
</div>
<div class='tb-fieldfilter-popup-buttons'>
<button class='tb-btn' data-turbofieldfilter-selectfieldfiltereditor-update=''>Update</button>
<a href='#' class='tb-btn-link' data-turbofieldfilter-selectfieldfiltereditor-cancel=''>Cancel</a>
</div>
</div>
</div>
</div>
</div>
</div>
Controller file
public function index(request $request)
{
$productFilterType = $request->input('productFilterType');
return view('pages.order',array(
'productFilterType' =>$productFilterType,
));
}
jquery
function productFilter(value) {
alert(value);
jQuery("#productFilterType").val(value);
jQuery("#tabForms").submit();
}
$(document).on('click','#inputTagFilterId',function(){
var label = $('#inputTagFilterId');
var filterid = label.attr('class');
alert(filterid);
$("."+filterid).click(function(){
$("#filterpop").show();
});
});
Am using filters to display the products accordingly.
I got filtered result correctly. But I cannot retain the filtered results at next filter.
i.e. Am using three filter.
Created at - Date filter
Price - Filter
Seller - Filter
Everything working separately.
But I cannot make it at the next next filtering results. Also, I cannot make the checked value to be checked and selected value to be selected. How can I do it? My code I given below:
Controller:
$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'));
And my Blade code:
#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>Home
</li>
<li class="active category">{{$main}}
</li>
</ul>
</div>
<div class="col-sm-6">
<div class="pull-right">
<ul class="bc-Produc-mlist">
<li>View:Sort :</li>
<li> Popular
</li>
<li> NewDiscount
</li>
<li>Price: LowHigh
</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><i class="fa fa-caret-right" aria-hidden="true"></i> {{$m}}</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>2
</li>
<li>3
</li>
<li>4
</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
In such scenario, you can use ajax() instead of form submit. But if you don't want to use ajax() and continue with the form submit approach then you have to maintain the state on your own. To do this you have to return from controller which elements are checked or what value is selected in dropdown and make it checked and selected on behalf of these values. laravel provide this approach return redirect with input
You can use it like:
return Redirect::back()->withInput(Input::all());
how can i get the id passed with the url and save it in an input ? and the controller is like that :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use URL;
use DB;
class productController extends Controller
{
//
public function getIndex(){
$in=URL::get('id');
$product=DB::table('products')->get(['id','name','salary','sale','p_salary','n_salary','best','type','image_name','category_id','sub_id','incategory_id','new']);
return view('contents.products')->with('product',$product)
->with('in',$in);
}
}
and the view is like that :
#extends('master')
#section('content')
<form method="POST" action="{{action('productController#getIndex')}}" enctype="multipart/form-code">
{!! csrf_field() !!}
<div class="em-wrapper-main">
<div class="container container-main">
<div class="em-inner-main">
<div class="em-wrapper-area02"></div>
<div class="em-wrapper-area03"></div>
<div class="em-wrapper-area04"></div>
<div class="em-main-container em-col1-layout">
<div class="row">
<div class="em-col-main col-sm-24">
<div class="page-title category-title">
<h1>Shoes</h1>
</div>
<div class="category-products">
<div class="toolbar-top">
<div class="toolbar">
<div class="pager">
<p class="amount"> Items 1 to 12 of 20 total</p>
<div class="pages">
<ol>
<li class="current">1</li>
<li>2
</li>
<li>
<a class="next i-next" href="#" title="Next"> <img src="{{asset('assets/images/pager_arrow_right.gif')}}" alt="Next" class="v-middle" /> </a>
</li>
</ol>
</div>
</div><!-- /.pager -->
<div class="sorter">
<p class="view-mode">
<label>View as:</label> <strong title="Grid" class="grid">Grid</strong> List
</p>
<div class="sort-by toolbar-switch">
<div class="toolbar-title">
<label>Sort By</label>
<select class="sortby" name="sortby">
<option value="position" selected="selected"> Position</option>
<option value="name"> Name</option>
<option value="price"> Price</option>
</select>
</div>
<a href="#" title="Set Descending Direction"><img src="{{asset('assets/images/i_asc_arrow.png')}}" alt="Set Descending Direction" class="v-middle" />
</a>
</div>
<div class="limiter toolbar-switch">
<div class="toolbar-title">
<label>Show</label>
<select class="toolbar-show">
<option value="12" selected="selected"> 12</option>
<option value="24"> 24</option>
<option value="36"> 36</option>
</select>
</div>
</div>
</div><!-- /.sorter -->
</div>
</div><!-- /.toolbar-top -->
<div id="em-grid-mode">
<ul class="emcatalog-grid-mode products-grid emcatalog-disable-hover-below-mobile">
#foreach($product as $p)
#foreach($in as $n)
#if($p->incategory_id == $n->id)
<li class="item first">
<div class="product-item">
<div class="product-shop-top">
<a href="{{action('productdetailController#getProduct' , array('id' => $p->id))}}" title="{{$p->name}}" class="product-image">
<img class="em-img-lazy img-responsive em-alt-hover" src="{{asset('images/')}}/{{$p->image_name}}" width="220" height="220" alt="WIASSI Version 1" />
<img id="product-collection-image-206" class="em-img-lazy img-responsive em-alt-org" src="{{asset('images/')}}/{{$p->image_name}}" width="220" height="220" alt="WIASSI Version 1" />
<span class="bkg-hover"></span> </a>
<div class="bottom">
<div class="em-btn-addto text-center ">
<button type="button" title="Add to Cart" class="button btn-cart" onclick="206"><span><span>Add to Cart</span></span>
</button>
<ul class="add-to-links">
<li><button type="submit" class="link-wishlist" name="submit" title="Add to Wishlist">Add to Wishlist</button>
</li>
<li>Add to Compare
</li>
</ul>
</div>
<div class="quickshop-link-container"> Quickshop
</div>
</div>
</div>
<div class="product-shop">
<div class="f-fix">
<h2 class="product-name text-center "> {{$p->name}} </h2>
<div class=" text-center">
<div class="ratings">
<div class="rating-box">
<div class="rating" style="width:%"></div>
</div> <span class="amount">(0)</span>
</div>
</div>
<div class="text-center ">
<div class="price-box"> <span class="regular-price" id="product-price-206"> <span class="price" content="{{$p->salary}}">${{$p->salary}}</span> </span>
</div>
</div>
<div class="desc std text-center em-element-display-hover">{{$p->name}}</div>
</div>
</div>
</div><!-- /.product-item -->
</li>
#endif
#endforeach
#endforeach
</ul>
</div><!-- /.em-grid-mode -->
<div class="toolbar-bottom em-box-03">
<div class="toolbar">
<div class="pager">
<p class="amount"> Items 1 to 12 of 20 total</p>
<div class="pages">
<ol>
<li class="current">1</li>
<li>2
</li>
<li>
<a class="next i-next" href="#" title="Next">
<img src="{{asset('assets/images/pager_arrow_right.gif')}}" alt="Next" class="v-middle" /> </a>
</li>
</ol>
</div>
</div><!-- /.pager -->
<div class="sorter">
<p class="view-mode">
<label>View as:</label> <strong title="Grid" class="grid">Grid</strong> List
</p>
<div class="sort-by toolbar-switch">
<div class="toolbar-title">
<label>Sort By</label>
<select class="sortby" name="sortby">
<option value="position" selected="selected"> Position</option>
<option value="name"> Name</option>
<option value="price"> Price</option>
</select>
</div>
<a href="#" title="Set Descending Direction"><img src="{{asset('assets/images/i_asc_arrow.png')}}" alt="Set Descending Direction" class="v-middle" />
</a>
</div>
<div class="limiter toolbar-switch">
<div class="toolbar-title">
<label>Show</label>
<select class="toolbar-show">
<option value="12" selected="selected"> 12</option>
<option value="24"> 24</option>
<option value="36"> 36</option>
</select>
</div>
</div>
</div><!-- /.sorter -->
</div>
</div><!-- /.toolbar-bottom -->
</div><!-- /.category-products -->
</div>
</div>
</div><!-- /.em-main-container -->
</div>
</div>
</div><!-- /.em-wrapper-main -->
</form>
#stop
how to get the products that have the incategory_id passed with the url ?
You could use the Request facade to get the id and then, use the where method to get the requested product like this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Request;
use DB;
class productController extends Controller
{
public function getIndex()
{
$in=Request::get('id');
$product=DB::table('products')->where('incategory_id', $in)->get(['id','name','salary','sale','p_salary','n_salary','best','type','image_name','category_id','sub_id','incategory_id','new']);
return view('contents.products')->with('product',$product);
}
}
Also, you could type-hint the Illuminate\Http\Request:
public function getIndex(Request $request)
{
$in=$request->get('id');
// ...
}