I use Laravel as an API on an Angular app. One of the controllers has to update an array of objects.

This array, coming from Angular, might have

The same objects but with different attributes One of the objects might have been deleted New objects

So, I cannot just update the objects I have, since I need to delete the records that are not on the array any more and also create the new records.

At the moment, I have a not-so-nice solution to delete all the previous records and create new based on the array. Like this:

Sample::where('contest_id', $request->get('contest_id')) ->where('type', '0') ->delete(); $samples = $request->get('samples'); foreach ( $samples as $sample ) { Sample::create($sample); }

However, I want to add an activity logger to keep track of changes, but the above solution doesn't help. The activity logger works like this:

activity() ->causedBy($user) ->performedOn($sample) ->withProperties($properties) ->log('update'); //or new or delete

Where $properties is this:

$properties = [ 'property' => [ 'old' => $old_sample, // empty on creating new record 'new' => $sample // empty on deleting old record ], ];

Anything you could suggest?