Reputation: 27
current table (TARGET)
field1 field2 field3 field4
apple1 apple2 apple3 apple4
The data I want to add (SOURCE)
SourceData = ("orange1","orange2",null,"orange4")
The result I expected after updating
field1 field2 field3 field4
orange1 orange2 apple3 orange4
I can do this with sql query, I just want to do it with laravel eloquent.
Anyone suggestion ? Thanks...
Upvotes: 0
Views: 87
Reputation: 2568
Let's say that you have find the model you want:
eg: $model = App\Target::where('field1', 'orange1');
You can use the update function:
App\Target::find(id)->update([
'field1' => 'orange1',
'field2' => 'orange2',
'field4' => 'orange4'
]);
The update
function updates only the specified fields.
If you want to update all rows, then the following does the trick:
App\Target::update([
'field1' => 'orange1',
'field2' => 'orange2',
'field4' => 'orange4'
]);
Upvotes: 1