Laravel - File Storage - File Visibility

In Laravel's Flysystem integration, "visibility" is an abstraction of file permissions across multiple platforms. Files may either be declared public or private. When a file is declared public, you are indicating that the file should generally be accessible to others. For example, when using the S3 driver, you may retrieve URLs for public files.

You can set the visibility when writing the file via the put method:

    
    use Illuminate\Support\Facades\Storage;
    
    Storage::put('file.jpg', $contents, 'public');
	

If the file has already been stored, its visibility can be retrieved and set via the getVisibility and setVisibility methods:

    
    $visibility = Storage::getVisibility('file.jpg');
    
    Storage::setVisibility('file.jpg', 'public');
	

When interacting with uploaded files, you may use the storePublicly and storePubliclyAs methods to store the uploaded file with public visibility:

    
    $path = $request->file('avatar')->storePublicly('avatars', 's3');
    
    $path = $request->file('avatar')->storePubliclyAs(
        'avatars',
        $request->user()->id,
        's3'
    );