1

I have ExampleRepository, who receives validated array, store it in db with some modification, and responses inserted/updated object. It uses function:

ExampleRepository:

public function store($validtedData)
{
    //some code
    return MyExampleModel::updateOrCreate(['id' => $id], [$modifiedData]);
}

Is it possible to understand, which action was used on object (update or insert)? I mean:

do not copy code below, such function not existence

$example = $this->exampleRepository->store($validatedData);

if ($example->justNewlyCreated())
    //do something
else
    //do something else

I don't need object_id nor other data, but only action used on object to store in db

Vasyl Zhuryk
  • 1,228
  • 10
  • 23
  • So you want to known if an insert happend or an update happend? Could you elaborate why you would need this? – MaartenDev Oct 12 '21 at 10:05
  • @MaartenDev Thank you! This is exactly I looking for, but unfortunately I didn't found it before I created the question – Vasyl Zhuryk Oct 12 '21 at 10:22

0 Answers0