Refreshes
Refresh database-generated columns after writes
Description: Defines the columns that should be re-read from the database after the model is inserted or updated, so values generated by the database (defaults, triggers, generated columns) are available on the model.
Namespace: Illuminate\Database\Eloquent\Attributes\Refreshes
Added in: Laravel 13.33
Usage
use Illuminate\Database\Eloquent\Attributes\Refreshes;
use Illuminate\Database\Eloquent\Model;
// Before:
protected array $refreshes = ['slug', 'version'];
use Illuminate\Database\Eloquent\Attributes\Refreshes;
use Illuminate\Database\Eloquent\Model;
// After:
#[Refreshes(['slug', 'version'])]
class Post extends Model
{
//
}
$post = Post::create(['title' => 'Hello World']);
$post->slug; // Value generated by the database
$post->version; // Value set by a database trigger
Variadic form is also supported:
#[Refreshes('slug', 'version')]
class Post extends Model
{
//
}
The refresh runs after save(), update(), increment() and decrement(), using the write connection. Refreshed columns are excluded when the model is copied with replicate().