Support the ongoing development of Laravel.io →
Database Eloquent Packages
Last updated 2 years ago.
0

Hello,

You can add attributes on models that do not have a corresponding column in your database, look at the end of the Eloquent documentation : This is a link But you cant orderBy on it, just sortBy.

Last updated 2 years ago.
0

Yeah, that's part of the solution. But I need to basically provide this query when searching for a user:

SELECT *, CONCAT(first_name, ' ', last_name) as full_name FROM users GROUP BY full_name

I got it working to a point where I append the column to the select, but then it wipes out any custom definition of columns from the get() or first() method, and I always return a * plus all the concatencated fields, which is not ideal.

The idea was to return the concatencated fields plus anything a user specifies in the get() or first() method.

Last updated 2 years ago.
0

You can try using

DB::raw("CONCAT(first_name, ' ', last_name) as full_name")

see documentation for more.

Last updated 2 years ago.
0

Yup, I did that already before, had an issue on how to append it in every query.

Everything is now well implemented in my Laravel Concatenator package.

https://github.com/slovenianGooner/concatenator

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.