How to save using condition in laravel?
Basically I want to save data in my model using condition to prevent multiple save data being performed simultaneously.
What I currently do now is:
$order = Order::find(id); $order->paid_amount = $amount; $order->status = $status; $order->save();
What I need is:
$order = Order::find(id); $order->paid_amount = $amount; $order->status = $status; $order->where('last_update', $last_update); $order->save();
Is it possible to do this in laravel efficiently or do I have to use raw sql or update?
I guess you mean "Is it possible to do this in eloquent efficiently or do I have to use raw sql or update?"
Anyway, I think you need the query builder to do what you want:
DB::table('order') ->where('id', $id) ->update([ 'paid_amount' => $amount, 'status' => $status; ]);
It is as atomic as you can get.
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?