thank you @automica
ok I will explain with image
when I make a filter section just "by category" and click the link of robe in 'by category' the products of robe display and there's no problem like this
https://i.imgur.com/7yH6ARy.png
and this is the code in category.blade.php:
<h3>By Category</h3>
<ul>
@foreach ($categories as $category)
@if ($category->id!=1)
<li class=""><a href="{{ route('category.show', $category->slug) }}">{{ $category->name }}</a></li>
@endif
@endforeach
</ul>
and in header there's the search bar , it works :
if i write bask in search bar it display all products in their name bask like bask, basket like this
search:
https://i.imgur.com/YmP1lXW.png
result:
https://i.imgur.com/mWVA24H.png
and if write x:
https://i.imgur.com/f0qI4yK.png
result : search failed please try again with all products
https://i.imgur.com/RG70Coa.png
and I made a filter section by price low_high high_low:
productcontroller:
if (request()->sort == 'low_high') {
$products = Product::where('status', '1')->orderBy('price')->paginate($pagination);
} elseif (request()->sort == 'high_low') {
$products = Product::where('status', '1')->orderBy('price', 'desc')->paginate($pagination);
} else {
$products = Product::where('status', '1')->OrderBy('name', 'asc')->paginate($pagination);
}
return view('site.pages.products', compact('products','categories' ));
}
products.blade.php:
<div>
<strong>Price: </strong>
<a href="{{ route('products.index', [ 'sort' => 'low_high']) }}">Low to High</a> |
<a href="{{ route('products.index', [ 'sort' => 'high_low']) }}">High to Low</a>
</div>
image:high_low:
https://i.imgur.com/b2F49BK.png
image :low_high:
https://i.imgur.com/Z0cYgjt.png
and this is code:
header.blade.php:
<div class="col-lg-6 col-sm-6">
<form action="{{ url('products') }}" class="search-wrap" method="post" >
@csrf
<div class="input-group">
<input type="text" name="q" id="q" class="form-control" placeholder="Search">
<div class="input-group-append">
<button class="btn btn-primary" type="submit">
<i class="fa fa-search"></i>
</button>
</div>
</div>
</form>
</div>
products.blade.php:
@extends('site.app')
@section('title', 'products')
@section('content')
<section class="section-content bg padding-y">
<div class="container">
<div class="row">
<aside class="col-sm-3">
<div class="card card-filter">
<div class="container">
@if (session()->has('success_message'))
<div class="alert alert-success">
{{ session()->get('success_message') }}
</div>
@endif
@if(count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
</div>
<div>
<div class="products-header">
<h1 class="stylish-heading"></h1>
<div>
<strong>Price: </strong>
<a href="{{ route('products.index', [ 'sort' => 'low_high']) }}">Low to High</a> |
<a href="{{ route('products.index', [ 'sort' => 'high_low']) }}">High to Low</a>
</div>
</div>
<!-- card-group-item.// -->
</div>
<!-- card.// -->
</aside>
<main class="col-sm-9">
<div id="code_prod_complex">
@if( session('status'))
<div class="alert alert-info">
{{ session('status')}}
</div>
@endif
<div class="container">
<div class="row">
@forelse($products as $product)
<div class="col-md-3">
<figure class="card card-product">
@if ($product->images->count() > 0)
<div class="img-wrap padding-y"><img src="{{ asset('storage/'.$product->images->first()->full) }}" alt=""></div>
@else
<div class="img-wrap padding-y"><img src="https://via.placeholder.com/176" alt=""></div>
@endif
<figcaption class="info-wrap">
<h4 class="title"><a href="{{ route('product.show', $product->slug) }}">{{ $product->name }}</a></h4>
</figcaption>
<div class="bottom-wrap">
<a href="{{ route('product.show', $product->slug) }}" class="btn btn-sm btn-success float-right">View Details</a>
@if ($product->sale_price != 0)
<div class="price-wrap h5">
<span class="price"> {{ config('settings.currency_symbol').$product->sale_price }} </span>
<del class="price-old"> {{ config('settings.currency_symbol').$product->price }}</del>
</div>
@else
<div class="price-wrap h5">
<span class="price"> {{ config('settings.currency_symbol').$product->price }} </span>
</div>
@endif
</div>
</figure>
</div>
@empty
<p>No Products found </p>
@endforelse
</div>
{{$products->links()}}
</div>
</main>
</div>
</section>
@stop
productcontroller:
public function search( Request $request) {
$request->validate([
'q' => 'required'
]);
$q = $request->q;
$products = Product::where('name', 'like', '%' . $q . '%')->where('status', '1')->paginate(15);
if ($products->count()) {
return view('site.pages.products')->with(
'products' , $products
);
} else {
return redirect('/products')->with(
'status' , 'search failed ,, please try again'
);
}
}
route:
Route::view('/', 'site.pages.homepage');
Route::get('/category/{slug}', 'Site\CategoryController@show')->name('category.show');
Route::get('/product/{slug}', 'Site\ProductController@show')->name('product.show');
Route::get('/products', 'Site\ProductController@index')->name('products.index');
Route::post('/products', 'Site\ProductController@search')->name('products.search');
when I click men->basket in navbar it works and I made the filter section (by category,by brand,...) with checkbox and select (it doesn't work and this is the problem) and this is the image
https://i.imgur.com/eoQsXzA.png
https://i.imgur.com/pyR2s13.png
so what I have to do now
I want to make this work and organize it step by step thank you very much