Local disk storage lets your Laravel app save files directly on your server's hard drive. This is useful for storing images, documents, or backups safely and quickly.
Local disk storage in Laravel
use Illuminate\Support\Facades\Storage; // Save a file Storage::disk('local')->put('filename.txt', 'File contents'); // Get a file $content = Storage::disk('local')->get('filename.txt'); // Delete a file Storage::disk('local')->delete('filename.txt');
The 'local' disk stores files in the storage/app folder by default.
Use the Storage facade to interact with files easily.
notes.txt with the text 'Hello Laravel!' inside the local storage folder.Storage::disk('local')->put('notes.txt', 'Hello Laravel!');
notes.txt from local storage and prints it.$content = Storage::disk('local')->get('notes.txt'); echo $content;
notes.txt file from local storage.Storage::disk('local')->delete('notes.txt');
This Laravel controller has three methods: one to save a file named example.txt with some text, one to read and return its content, and one to delete the file. It uses the local disk storage.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; class FileController extends Controller { public function saveFile() { Storage::disk('local')->put('example.txt', 'This is a test file.'); return 'File saved successfully!'; } public function readFile() { if (Storage::disk('local')->exists('example.txt')) { $content = Storage::disk('local')->get('example.txt'); return $content; } return 'File not found.'; } public function deleteFile() { Storage::disk('local')->delete('example.txt'); return 'File deleted successfully!'; } }
Files saved on the local disk are stored in storage/app. You can change this path in config/filesystems.php.
Remember to run php artisan storage:link if you want to make files publicly accessible via public/storage.
Local disk storage is fast but only works on the server where your app runs.
Local disk storage saves files on your server's hard drive inside storage/app.
Use the Storage facade with disk('local') to put, get, and delete files.
This method is great for quick, private file storage during development or on your own server.