Laravel's File Storage abstraction layer allows you to manage files across local, cloud, and remote storage systems. It uses the Flysystem library to provide a variety of storage drivers, including Amazon S3, FTP, and local storage.
Laravel's file storage system uses Flysystem, a PHP library for file storage. It provides a uniform API for working with various storage backends.
Configure storage in config/filesystems.php
:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
Store a file:
use Illuminate\Support\Facades\Storage;
Storage::disk('local')->put('example.txt', 'File contents here');
Retrieve a file URL:
$url = Storage::disk('s3')->url('example.txt');