
File Storage
Filesystem configuration, local disk, S3, file uploads, file operations, visibility, symbolic links, streaming
1Which Laravel configuration file defines file storage disks?
Which Laravel configuration file defines file storage disks?
回答
The config/filesystems.php file centralizes all storage system configuration in Laravel. It defines available disks (local, public, s3), their respective drivers, and specific parameters like root directory, default visibility, or cloud credentials. This centralization allows easy switching between different storage backends without modifying business logic code.
2Which method allows storing content directly into a file with Laravel Storage?
Which method allows storing content directly into a file with Laravel Storage?
回答
The Storage::put() method accepts a path and content (string or resource) to create or overwrite a file. It returns a boolean indicating operation success. This method is ideal for storing dynamically generated content like CSV exports, JSON reports, or content downloaded via API. For form uploads with UploadedFile, putFile() or putFileAs() are more appropriate.
3Which Laravel disk stores files publicly accessible via URL?
Which Laravel disk stores files publicly accessible via URL?
回答
The public disk stores files in storage/app/public and uses a symbolic link to public/storage to make them accessible via HTTP. The php artisan storage:link command creates this symbolic link. This disk is configured with public visibility by default, allowing direct file access via URLs like /storage/avatars/user.jpg. It suits user assets like avatars, profile images, or public documents.
Which method checks if a file exists in the storage system?
Which Artisan command creates the symbolic link for the public disk?
+15 面接問題