Tuesday, February 28, 2017

[SOLVED]Laravel search mutiple fields

i currently have a search function on my website, i need it to search 3 fields - appid, mobilenumber, email .
Right now once the user enters the data in the search box it searches all 3 but its not working.
Data is collected using GET.
Here is my query
http://www.example.com/?id=1&searchall=07853637362
    $mobile = INPUT::get('searchall');
    $email = INPUT::get('searchall');
    $appid = INPUT::get('searchall');

$data = DB::table('leads')
->when($mobile, function($query) use ($mobile){
                return $query->where('MobilePhone', $mobile);
            })

            ->when($email, function($query) use ($email){
                return $query->where('Email', $email);
            })

            ->when($appid, function($query) use ($appid){
                return $query->where('AppID', $appid);
            })

->get();

So i need it to search each field until it finds the correct field value.



via ALCHI

Advertisement