NightM4re
3 years ago

Problem with scope

Posted 3 years ago by NightM4re

Hi everyone, I am trying to use scope for find a user with a search form. In this search I want to put first_name (nombres) and last_name (apellidos) and the scoope can find what user I want. Here is my scoope and my controller Scope

public function scopeApellidos($query, $apellidos) {
        if ($apellidos != "") {
            return $query->where(\DB::raw("CONCAT(nombres, ' ', apellidos)"), $apellidos);
        }
        return $query;
    }

Controller

$users = User::orderBy('apellidos')->email($request->email)->apellidos($request->apellidos)->type($request->type)->get();

The problem is that debugbar say

select * from users where CONCAT(nombres, ' ', apellidos) = 'cabrera' order by apellidos asc

but I dont recieve any user in my usertable but I have one that have last_name (apellidos) cabrera Thanks for help me

Please sign in or create an account to participate in this conversation.