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



via Chebli Mohamed

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



via Chebli Mohamed

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.



via Chebli Mohamed

lundi 4 juillet 2022

Laravel ReflectionException : Class CustomerAccountController does not exist

I have this project on Laravel 5.7 and Voyager on WAMP with 2 issues, the first one is when I run php artisan route:list and the result is:

 ReflectionException  : Class CustomerAccountController does not exist
 at C:\wamp64\www\cell_marketplace\vendor\laravel\framework\src\Illuminate\Container\Container.php:779

And actually the class exists and I'm using its functions on another processes and it's working, I've checked namespace, ran composer dump-autoload with no results.

The second one, I've created a BREAD on Voyager, and I got the model class and controller class, but when I go to the index of that resource again got this:

 ReflectionException: Class DropOffController does not exist in \vendor\laravel\framework\src\Illuminate\Container\Container.php:779

And the controller exists and has a function that it's actually working, so I think that's related with the first one but if anybody can help I'd really appreciate it



via Chebli Mohamed

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?



via Chebli Mohamed

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.



via Chebli Mohamed

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";
  }

}


via Chebli Mohamed