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']);
            }   
        }

Recommended Answers

All 8 Replies

Still cant figure it out

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...

doesnt work ive tryied all...

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.

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();

You must use $query inside the function as explained in the documentation:

Also set the debug to TRUE in your app/config/app.php file, to see the errors. And check in app/storage/logs/ for the generated error logs.

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']);
        }   
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.