mercredi 6 juillet 2022

laravel query to sort product based on other database table

Sorting product We have two tables

  1. products(contain all products)
  2. product_sort_order (see below screenshot) (table contain sorted products with column sort_order)

I need to display sorted products with the help of sort_order in product_sort_order table.Simple is that. What modification should I do to get sorted results from product_srot_order tables. Please suggest some solutions.

enter image description here

Note: section = third level of category

    $q = Product::query();
    $q->where('sub_category_id', $sub_category_id);
    $q->where('status', '=', 1);
    $q->where('is_pendding', '=', 0);
    // $q->where('status', '=', 1);

    $q->where('sub_category_id', $sub_category_id);
    // offer check.
    if ($request->get('theme')) {
        $q->Where('theme_id', 'LIKE', '%' . $request->get('theme') . '%');
    }
    // category check.
    if ($request->get('categories')) {
        $q->where('category_id', getCategoryIdFromSlug($request->get('categories')));
    }

    if ($request->get('sections')) { // third level of category

        $q->where('section_category_id', getSectionIdFromSlug($request->get('sections')));
     
       

    }

    // product language
    if ((App::getLocale()) == 'en') {
        // $q->orderBy('product_name_lang->en');
    } else {
        // $q->orderBy('product_name_lang->fr');
    }

    if ($request->get_j0_product == true) {
        $q->where('delivery', 'J0');
    }
    

    $products = $q->paginate($this->paginationcount);

    $data['paginationproducts'] = (excludeProductLessThanZero($products));


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2JAWOT7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire