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

[DB] Allow DB::raw expressions as a value for mass update #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bradleybernard
Copy link

Why

Allow passing in DB::raw Expressions so that the compiled CASE WHEN can use the current column values.

How

Hook into $value inspection code and add a case for Illuminate\Contracts\Database\Query\Expression type. Pull out the raw string value by passing along the query's current grammar (Illuminate/Database/Query/Grammars/Grammar).

Ex

User::massUpdate([
   [ 'id' => 1, 'receipt_limit' => DB::raw('receipt_limit - 1']
]);

Before this change, it would quote this value: receipt_limit = 'receipt_limit - 1' which wasn't valid SQL syntax. With the change, it behaves as expected.

@iksaku
Copy link
Owner

iksaku commented Jan 16, 2024

Love this!
Could you please add some tests for this specific use case?

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.

None yet

2 participants