Laravel 13.26 New Published on

Migrating files as they are read with read-through

A read-through disk reads the new storage, falls back to the old one and copies over what it finds there: the migration happens by itself.

Topics covered: Storage

New in Laravel 13.26. To move files to new storage without copying everything at once, you had to write the fallback by hand: read the new disk, otherwise the old one, and copy the file over along the way. The read-through driver does exactly that.

Before

if (Storage::disk('new')->exists($name)) {
    return Storage::disk('new')->get($name);
}
$contents = Storage::disk('old')->get($name);
Storage::disk('new')->put($name, $contents);

Since Laravel 13.26

// config/filesystems.php
'documents' => [
    'driver' => 'read-through',
    'primary' => 'new',
    'fallback' => 'old',
],
Storage::disk('documents')->get($name);

The disk reads primary first. A file that only exists on fallback is returned, then copied to primary for next time. Writes and file listings target primary.

Your task

Declare a read-through disk named documents in config/filesystems.php, then simplify DocumentController: it must no longer know about the old storage.

Where the feature comes from: the original pull request.