lundi 17 octobre 2016

How can I retrieve data from a table in laravel with multiple array conditions

Im applying a search filter in a e-commerce website. Here the Customer can choose various fields like color, shape, price, symmetry,polish,clarity and various other things. While the Customer selects any option it should add to the last option he have selected.So he/she may have combination of condition which have to be fetched and shown. For one array condition i can use whereIn in laravel but for multiple array conditions what should I use.Im not sure which array will be empty.

Here is my code for filter :-

public function Filter(Request $request)
{
    $conditions = array();
    if($request->isMethod('post')) {
        $data = array_filter($request->all());

        $shapes = array();
        $amount = array();
        $carat  = array();
        $cut  = array();
        $color = array();
        $clarity = array();
        $cerifying_agency = array();
        $flourscence = array();
        $polish = array();
        $symmetry = array();
       // $conditions=array();
        if(isset($data['shape'])){
            $shapes = $data['shape'];
        }
        if(isset($data['amount'])){
            $amount = $data['amount'];
        }
        if(isset($data['carat'])){
            $carat = $data['carat'];
        }
        if(isset($data['cut'])){
            $cut = $data['cut'];
        }
        if(isset($data['color'])){
            $color = $data['color'];
        }
        if(isset($data['clarity'])){
            $clarity = $data['clarity'];
        }
        if(isset($data['ca'])){
            $cerifying_agency = $data['ca'];
        }
        if(isset($data['fl'])){
            $flourscence = $data['fl'];
        }
        if(isset($data['polish'])){
            $polish = $data['polish'];
        }
        if(isset($data['symmetry'])){
            $symmetry = $data['symmetry'];
        }

    }
}

I have attached the snapshot of the UI and the data format for ajax which is being called in the array of the filter function :-Sorry I couldnt embed the picture as Stackoverflow is not allowing me to do so



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire