samedi 2 janvier 2016

filter data in laravel 5

My view is like this :

...
<span class="opensans size13"><b>Gender</b></span>
                <select class="form-control" name="gender" id="gender" placeholder="Gender">
                  <option value="" selected="">Gender</option>                      
                  <option value="M">Male</option>
                  <option value="F">Female</option>                       
                </select>   
            <span class="opensans size8" style="color: red;"></span>                                                    
            <div class="clearfix pbottom15"></div>

            <span class="opensans size13"><b>Published</b></span>
                <select class="form-control" name="published" id="published" placeholder="Published">
                  <option value="" selected="">Published</option>                       
                  <option value="YES">YES</option>
                  <option value="NO">NO</option>                          
                </select>   
            <span class="opensans size8" style="color: red;"></span>    
...

<div class="col-md-5">
                <div class="right wh70percent">
                    <select class="form-control" name="status_sort" id="status_sort" placeholder="Status">
                      <option value="" selected="">Status</option>                      
                      <option value="N">N</option>
                      <option value="BL">BL</option>                          
                    </select>
                </div>
            </div>
...     

My service is like this :

public function dataCustomerList($param) 
    {
        $status = $param['status_sort'];
        $gender = $param['gender'];
        $published = $param['published'];

        if($published=='NO'){
            $published_check = 'NO';
            $published = 0;
        }
        else if($published=='YES'){
            $published_check = 'YES';
            $published = 1;
        }

        if(empty($status)) 
            $customer = customer::paginate(10);
        else
            $customer = customer::where('tb_customer.customer_status', '=', $status)
                                ->paginate(10);

        if(!empty($gender) AND !empty($published_check)){
            $customer = customer::where('tb_customer.gender', '=', $gender)
                                ->where('tb_customer.published', '=', $published)
                                ->paginate(10);
        }
        else if(!empty($gender)){
            $customer = customer::where('tb_customer.gender', '=', $gender)
                                ->paginate(10);
        }
        else if(!empty($published_check)){
            $customer = customer::where('tb_customer.published', '=', $published)
                                ->paginate(10);
        }
        return $customer;  
    }   

The interface is like this : http://ift.tt/1RXBUCt

When I just choose published and gender and then press the search button, data are displayed according.

When I only select status, the displayed data in accordance.

But when I choose the gender, published and status, the displayed data do not match.

I want to ask again. In addition to my code, whether there are other simpler code?

Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire