disk [users] not configured, please add a disk config in `config/filesystems.php`

Viewed 31
  • PHP version PHP/8.1.10
  • Laravel version 9.28.0

While working on a Laravel-admin backend, I tried creating a new user (basically inserting data into admin_user table in the database)

working on my windows computer, I encountered the error:

disk [users] not configured, please add a disk config in config/filesystems.php.

I revisited the Laravel docs and these are the things I did to solve the problem:

  1. Opened the config/admin.php and added:
'disk' => 'users',

         // Image and file upload path under the disk above.
         'directory' => [
            'image' => 'images',
            'file'  => 'files',
        ],
  1. Then opened the config/filesystems.php and added:
'users' => [ 
            'driver' => 'local', 
            'root' => storage_path('app'),
             ]
  1. Closed my git bash and reopened it, ran:
php artisan serve
  1. Accessed the page for creating a user and the error was solved..

Do you know any other way this could be solved?

1 Answers

To use a custom disk you must configure it first. To configure a disk, follow the following steps:

  1. Open filesystems.php file, under config directory, in your preferred text editor or IDE.
  2. Look for the key named disks. The array under disks is where you configure your disks. Laravel already provides some disks out of the box (I recommend not messing with them unless you know what you are doing).
  3. Add your new disk configuration, something like:
'users' => [
    'driver' => 'local',
    'root' => storage_path('app/public/users'),
    'url' => env('APP_URL').'/storage/users',
    'visibility' => 'public',
]

Note: The above example assumes you have already executed php artisan storage:link command in order to create a symbolic link that allows the files in storage/app/public to be accessible from outside.

  1. Save the file and now you can use that new disk like below:
use Illuminate\Support\Facades\Storage;

// initialize a new disk using the `users` disk config
$disk = Storage::disk('users');

// perform actions under that disk
$disk->delete('sub/folder/file.ext');

Also, it is important to note that you are not limited to have disks under the storage folder, you can actually have disks under the public folder:

'users' => [
    'driver' => 'local',
    'root' => public_path('/users'),
    'url' => env('APP_URL').'/users',
    'visibility' => 'public',
]

Note that the function public_path is used instead of storage_path. Also the command php artisan storage:link is not needed when your disks are under the public folder.

Learn more about File Storage in Laravel.

Related