mercredi 28 février 2018

laravel db sql query or

this my laravel query

$Product = Product::select('id','ProductWorkpiece','ProductCategory','ProductName','ProductImage','ProductSubCategory')
        ->where('ProductCategory',$category)
        ->where(function ($query) use ($ProductWorkpiece,$ProductMaterial,$ProductSubCategory,$ProductBrand) {

     foreach($ProductBrand as $key => $ProductBrandd) {
                if (!empty($ProductBrandd) && empty($subcategory)) {
                $query->orWhere('ProductBrand', '=', $ProductBrandd);
                    }
                 foreach($ProductSubCategory as $key => $subcategory) {
                if (!empty($ProductBrandd) && !empty($subcategory)) { 
                  $query->where('ProductSubCategory', '=', $subcategory);
                        }
                    }
                }
    })->where('Status','=','1')->get();

actually works but there is a strange one, when i click 1 check box works but when i click to 2 why not work by example I have a brand with the name sisma and have 2 product subcategory with the name Laser Marking Machine brand sisma when I checked brand sisma, out 2 product and when I checked the subcategory Dot Marking Machine and both items are missing. and that's right and when I checked the subcategory Laser Marking Machine and 2 the product did not come out and when I unchecked the Dot Marking Machine stuff came out and I call it strange that it should be without unchecked can be seen 2 product

if you still dont understand, watch this video is only 12 seconds https://youtu.be/fY417NsZmHI

and this is my manual sql ,it works well

SELECT * FROM Product WHERE ProductCategory = 'Marking' AND ProductBrand = 'Sisma' and ProductSubCategory = 'Dot Marking Machine' 
or ProductSubCategory = 'Laser Marking Machine' 

thanks for help



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

Aucun commentaire:

Enregistrer un commentaire