vendredi 24 avril 2020

how i can use like query in aes_encryption in laravel

How i can use like search query in Aes_encryption data in laravel .my data in tables is in AES Encryption form . i try this code but its not work well. please help me. Thanks in Advance.

     public static function search($type, $value, $limit = 12){
        $key = self::encryption_key;
        if($type == "name"){
           $valuess =  DB::raw("AES_ENCRYPT('$value',$key)");
            $values = Crypt::encrypt($valuess);
        }elseif($type == "phone"){
            $valuess =  DB::raw("AES_ENCRYPT('$value',$key)");
            $values = Crypt::encrypt($valuess);
        }elseif($type == "email"){
            $valuess =  DB::raw("AES_ENCRYPT('$value',$key)");
            $values = Crypt::encrypt($valuess);
        }elseif($type == "tag"){
            $values = $value;
        }else{
            $valuess =  DB::raw("AES_ENCRYPT('$value',$key)");
            $values = Crypt::encrypt($valuess);
        }
        $types = Customer::getTranslatedType($type);
        $user_id = Auth::user()->id;
        $data = DB::table("user_customers")->select(DB::raw("customers.status, customers.id, user_customers.tag as tag, SUM(CASE WHEN uploads.views=0 AND folders.isPrivate = 0 THEN 1 ELSE 0 END) as unread, 
        SUM(CASE WHEN uploads.status=1 AND folders.isPrivate = 0 THEN 1 ELSE 0 END) as unprocessed, companies.id as company_id ," .(new static)->columnsToAESDecryptHelper(array("companies.name" => "name",  "companies.email" => "email", "companies.phone" => "phone", "companies.address" => "address"))))
            ->join("customers", "customers.id", "user_customers.customer_id")
            ->join("users", "user_customers.user_id", "users.id")
            ->leftjoin("folders", "users.id", "folders.user_id")
            ->leftjoin("uploads", "folders.id" , DB::raw("uploads.folder_id AND customers.id = uploads.customer_id"))
            ->leftjoin("companies", "user_customers.company_id", "companies.id")
            ->where("user_customers.user_id", $user_id)
            ->where($types, 'LIKE',"%{$values}%")
//            ->groupBy(DB::raw("customers.id , customers.user_id"))
            ->groupBy(DB::raw("companies.id"))
            ->orderBy('customers.id','desc')
            ->paginate($limit);
       // dd($data);
        return $data;


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

Aucun commentaire:

Enregistrer un commentaire