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

mardi 5 juillet 2022

After click on print function() in javascript if I cancle print window my dashboard sidebar dropdown not working

After click on print function() in javascript if I cancle print window my dashboard sidebar dropdown not working.enter image description here

This error is showing in console. enter image description here



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

SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from `sessions` where `id` = Me2dEG11Zq4pJBhzCoWlhZwZuWPebKdGPLyhuleg limit 1)

I have a problem, my web site was working without problems, but when I enter any product, the web site does not work and gives this error I made

php artisan cache:clear
php artisan key:generate
php artisan cache:clear
php artisan make:command FlushSessions
php artisan session:flush

And I Deleted the data into the sessions table inside the Database But the problem has not been resolved



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

getting infinite loop - adding scope on user model with traits

after adding the following trait to the user model, I get a 500 error because of an infinite loop.

    trait Multitenantable
    {
        public static function bootMultitenantable()
        {
            static::addGlobalScope('tenant_id', function (Builder $builder) {
                $tenant_id = 1;
                if ( auth()->check() )
                {
                    $tenant_id = Auth::user()->tenant_id;
                }
    
                $builder->where('tenant_id', '=', $tenant_id);
            });
        }
    }

when I remove either the trait from the user model or the if containing the auth() part (lines 7,8,9,10) from this trait, the infinite loop resolves.

I'm not familiar with the magic behind laravel, could someone explain why this happens?

and how I could add global scope for multitenancy to the user model like the others?

I've followed this instruction to add multitenancy to my laraval project.



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

lundi 4 juillet 2022

whereJsonContains is not working with array of strings

I have a JSON stored on to my table column valid_dates:

{"weeks": [8], "endDate": "2022-06-02", "startDate": "2022-07-03"}

I am generating dates range by:

$from = Carbon::now()->addDays(-200);
        $from = Carbon::now()->addDays(-200);
        $to = Carbon::now();
        $past_dates = CarbonPeriod::create($from, $to)->toArray();
        $date_strings = [];
        foreach ($past_dates as $date) {
            $date_strings[] = $date->format('Y-m-d');
        }

Now when I have all the date in $date_strings array according to the format in database, when I try to query it via whereJsonContains():

->whereJsonContains('valid_dates->startDate',[$date_strings]) // this doesn't work

Nothing is returned however there are records with matching dates, but the opposite is the case when I try using a single date here as:

->whereJsonContains('valid_dates->startDate','2022-07-03') //this works

I wonder what could I be missing here, I have also checked Laravel docs and found the syntax similar to what I have.

Moreover is there any relaible way to compare data in whereJsonContains() using operators?



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

dimanche 3 juillet 2022

can we use payment network tokenization in the backened code?

as a part of our project we would like to implement a few more functionalities like Apple Pay,Google Pay and PayPal using autherize.net for billing payment transactions. In our project we already implemented autherize.net for card payments. Payment methods are implemented in the backend code side (using Laravel 5.5) with autherize.net APIs.There is no front end code interactions for card payment. User details needed for billing payments like Card details, auth_customer_id etc are fetched (today's user payment transaction due ) by running a crone job everyday. In Autherize.net documentation it is written Apple Pay uses payment network tokenization. We would like to know, is it possible to use payment network tokenization in the backend development(using Laravel 5.5) to implement Apple Pay,Google Pay, PayPal for billing payment transactions.



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

vendredi 1 juillet 2022

how to use custom rule in middleware of laravel 9.x?

NOTE: this is for an endpoint. not for a form request.

let's say I have middleware named Inputs which has this code in the handle()

public function handle(Request $request, Closure $next) {

  $data = $request->all();
   
  foreach ($data as $array) {
      //HOW TO USE THE CUSTOM RULE HERE?
  }
  return next($request);

}

here's the custom rule App\Rules

class MyRule {


  public function construct() {}

  public function passes($attribute, $value) {
       if ($value > 1) {
          return false;
       }
      return true;
  }

  public function message() {
      return "data invalid";
  }

}


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