0

Hy i have a search that now its works only if write or the first name or the last name, both didnt work....fn+ln....what i need to change?...ive tryied JOIN but nothing...

if (Input::has('name'))
        {
            $name = Input::get('name');
            $name = T_entity_details::where('First_Name','LIKE','%'.$name.'%')
            ->where('Last_Name','LIKE','%'.$name.'%','OR')
            ->where('Entity_Id','!=',$this->userId)
            ->get(array('Entity_Id'))
            ->toArray();
            $array1 = [];
            foreach ($name as $value) {
                array_push($array1, $value['Entity_Id']);
            }   
        }else{
            $name = T_entity_details::where('Entity_Id','!=',$this->userId)
            ->get(array('Entity_Id'))
            ->toArray();
            $array1 = [];
            foreach ($name as $value) {
                array_push($array1, $value['Entity_Id']);
            }   
        }
4
Contributors
8
Replies
51
Views
3 Years
Discussion Span
Last Post by bolfescu
0

You need to use orWhere() and/or andWhere() in your query instead of using all where(). It is simply a logic that can be translated to English...

0

Try this:

$name = Entitydetail::where(function($query) use($fname, $lname, $userID)
        {
            $query->where('First_Name','LIKE','%'.$fname.'%')
                  ->where('Last_Name','LIKE','%'.$lname.'%');
        })
        ->where('Entity_Id','!=', $userID)
        ->get(array('Entity_Id'))
        ->toArray();

dd("<pre>".print_r(DB::getQueryLog(),true)."</pre>");

By using DB::getQueryLog() you can see the query created by Laravel. The above will return:

Array
(
    [0] => Array
        (
            [query] => select `Entity_Id` from `entitydetails` where (`First_Name` LIKE ? and `Last_Name` LIKE ?) and `Entity_Id` != ?
            [bindings] => Array
                (
                    [0] => %John%
                    [1] => %Doe%
                    [2] => 1
                )

            [time] => 0.22
        )
)

If it doesn't work post your updated code.

Edited by cereal

0

i've tryied like this and still can figure it out..

    $name = T_entity_details::where(function($query) use($name, $name)
        {

            ->where('First_Name','LIKE','%'.$name.'%')
                  ->where('Last_Name','LIKE','%'.$name.'%');
        })
        ->where('Entity_Id','!=',$this->userId)
        ->get(array('Entity_Id'))
        ->toArray();
0

i have like this that array 1 its at the end the query

        $name = T_entity_details::where('First_Name','LIKE','%'.$name.'%')
        ->where('Last_Name','LIKE','%'.$name.'%','or')
        ->where('Entity_Id','!=',$this->userId)
        ->get(array('Entity_Id'))
        ->toArray();
        $array1 = [];
        foreach ($name as $value) {
            array_push($array1, $value['Entity_Id']);
        }   
    }else{
        $name = T_entity_details::where('Entity_Id','!=',$this->userId)
        ->get(array('Entity_Id'))
        ->toArray();
        $array1 = [];
        foreach ($name as $value) {
            array_push($array1, $value['Entity_Id']);
        }   
    }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.