Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
Select option table data search in laravel

I already show data from database in a table. Then made a condition if product stock=0 then show some html 'out of stock' and else show product quantity. Now I want to search by option In Stock And out stock. When click In stock then I want to see all in stock product in the table and same function use in Out of stock.

here is my controller

public function all_products(Request $request) {

    // $categories = Category::all(); 

    $col_name = null;
    $query = null;
    $seller_id = null;
    $sort_search = null;
    $products = Product::orderBy('created_at', 'desc')->where('auction_product',0);
    if ($request->has('user_id') && $request->user_id != null) {
        $products = $products->where('user_id', $request->user_id);
        $seller_id = $request->user_id;
    }
    if ($request->search != null){

        $searchString = $request->search;

        $products = $products
                    ->where('name', 'like', '%'.$request->search.'%')
                    ->orWhere('barcode', 'like', '%'.$request->search.'%')
                    ->orWhereHas('stocks', function ($query) use ($searchString) {
                        $query->where('sku', 'like', $searchString.'%');
                    });
                    
        $sort_search = $request->search;
    }
    if ($request->type != null){
        $var = explode(",", $request->type);
        $col_name = $var[0];
        $query = $var[1];
        $products = $products->orderBy($col_name, $query);
        $sort_type = $request->type;
    }

    $products = $products->paginate(50);
    $type = 'All';

    return view('backend.product.products.index', compact('products','type', 'col_name', 'query', 'seller_id', 'sort_search'));
}

and here is my blade page

<div class="col-md-2 ml-auto">
                
                <select class="form-control form-control-sm aiz-selectpicker mb-2 mb-md-0" name="type" id="type" onchange="sort_products()">
                    
                    <option value="">{{ translate('Sort By') }}</option>
                    
                    <option value="num_of_sale,desc"@isset($col_name , $query) @if($col_name == 'num_of_sale' && $query == 'desc') selected @endif @endisset>{{translate('In Stock')}}</option>
                    <option value="status,asc"@isset($col_name , $query) @if($col_name == 'status' && $query == 'asc') selected @endif @endisset>{{translate('Out Of Stock')}}</option>

                </select>
                
            </div>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!