# UpdateOrCreate may not update timestamp

Consider the following code which is part of a spreadsheet import of a product catalogue.

```php
    Item::updateOrCreate(
        ['code' => $row[0]],
        [
            'description'=> $row[1],
            'category'=> $row[2],
            'uom' => $row[3],
            'case_quantity' => $row[4],
            'each' => intval(strval($row[5]*100)),
            'generic' => false
    ]);
```

Using the Eloquent `model:updateOrCreate()`, if the spreadsheet contains any new items then a new record is added to the product catalogue.

If the Item already exists, but for instance, the price has changed then the existing record is found and updated.

However if the row in the spreadsheet is IDENTICAL to the record already in the database, then Eloquent knows that the record does not have any changes (is not dirty) and skips the write process. In this scenario, the `updated_at` field retains the previous value.

This might be ok for your use case, but in one project, the updated\_at column was being used as part of a scope to show only *current* products to the user.

The solution is to add `updated_at` to the data to be written to force a new value, and to ensure that updated\_at is in the `$fillable` array or unguarded.

```php
    Item::updateOrCreate(
        ['code' => $row[0]],
        [
            'description'=> $row[1],
            'category'=> $row[2],
            'uom' => $row[3],
            'case_quantity' => $row[4],
            'each' => intval(strval($row[5]*100)),
            'generic' => false,
            'updated_at' => now(),
    ]);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://talltips.novate.co.uk/laravel/updateorcreate-may-not-update-timestamp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
