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.
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.
You can try using
DB::raw("CONCAT(first_name, ' ', last_name) as full_name")
see documentation for more.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community