This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

jrcmadushanka50335
jrcmadushanka50335

I need to create a query as following.

$user = User::select("users.*",DB::raw("CONCAT(users.first_name,' ',users.last_name) as full_name" ->get();

and then I need to use the full_name on an advanced where clause.

I tried above laraval code and doesn't worked at all. Is there are any method to do this without using raw queries ?

Flynsarmy
Flynsarmy

Try this

User::select('*')->addSelect(Db::raw("CONCAT(first_name,' ',last_name) as full_name"))->whereRaw("CONCAT(first_name,' ',last_name) = 'Full Name'")->get();
daftspunky
daftspunky

That's right, I'm not sure you can query these computed columns in your where SQL statement, so you have to compute them again in the query, as flynsarmy pointed out

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.