Laravel Filesystem


This section will go over how the Files module integrates with Laravel's filesystem.

Storage Disks

Disks in the Files module are automatically configured as Laravel storage disks.

You may use the disk method on the Storage facade to work with files on a particular disk using the disk's slug:

Storage::disk('local')->put('avatars/me.jpg', $fileContents);
**Note:** You don't HAVE to use disks from the Files module. If the disk does not exist in the Files module Laravel's filesystem will work just as it would natively.

Retrieving Files

Accessing files on a disk from the Files module works just the same as native behavior. Note, however, that you must include a folder reference since all files in the Files module belong to a folder:

$contents = Storage::disk('local')->get('example_folder/file.jpg');

$exists = Storage::disk('local')->exists('example_folder/file.jpg');

Storing Files

When you store files on a disk from the Files module the file entry will be automatically synced into the database:

Storage::disk('local')->put('example_folder/file.jpg', $contents);

Storage::disk('local')->put('example_folder/file.jpg', $resource);


Folders in the Files module act just like directories. Being that a file in the Files module requires a folder you must always define the folder path if using the Laravel filesystem with files from the Files module.

foreach ($file in Storage::disk('local')->files('example_folder')) {
    echo $file->name;
Creating Directories

When you create a directory in Laravel on a disk from the Files module the resulting folder will be added automatically to the Files module:

Storage::makeDirectory('My Folder'); // Makes a folder like my_folder named "My Folder"

Folders are always referred to by their slugs in the Files module. Even though they have a name field.{.important}

Deleting Directories

When you delete a directory in Laravel on a disk from the Files module the resulting folder and files will be deleted automatically in the Files module: