I have such code in the controller:
for($i=0; $i<$number_of_tourists; $i++) {
$tourist = Tourist::updateOrCreate(['doc_number' => $request['doc_number'][$i]],
$tourist_to_update);
}
so, the updateOrCreate method can 1) Update record, 2) Create a new one 3) Leave record untouched if $tourist_to_update equals to what's already in the DB.
I want to save $tourist_to_update into $array[] only when a record in 'tourist" table is being updated (not when a new record created or nothing changes).
As I know, there are Eloquent events https://laravel.com/docs/5.4/eloquent#events which have updating and updated events, which seem to match my needs.
The problem is I watched&read several tutorials and still don't understand how to use them.
I know how-to-register a Eloquent event in Tourist model:
protected static function boot()
{
parent::boot();
static::updating(function ($model) {
});
}
Could anyone explain how can I achive my goal with Eloquent events?
Thank you in advance.