Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Added rawValue to Database Query Builder (and Eloquent as wrapper) #44631

Merged
merged 1 commit into from
Oct 19, 2022
Merged

Conversation

eusonlito
Copy link
Contributor

Currently there are a method to get a existing column value from database called value, this PR adds the method rawValue to get a value from a SQL expression.

For example, get first and last year from trip table using the Trip Model.

$first = TripModel::orderBy('date_at', 'ASC')->rawValue('YEAR(`date_at`)');
$last = TripModel::orderBy('date_at', 'DESC')->rawValue('YEAR(`date_at`)');

Or full name from the user table:

$fullname = UserModel::where('id', $id)->rawValue('CONCAT(`first_name`, " ", `last_name`)');

I think that there are a lot of usage cases for this method :)

Regards!
Lito.

@eusonlito eusonlito changed the title Added rawValue to Database Query Builder (and Eloquent as wrapper) [9.x] Added rawValue to Database Query Builder (and Eloquent as wrapper) Oct 18, 2022
@taylorotwell taylorotwell merged commit ae4b96a into laravel:9.x Oct 19, 2022
@eusonlito
Copy link
Contributor Author

Thanks @taylorotwell 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants