Why do I get an InvalidArgumentException: "Driver [] is not supported" error in Laravel?
The InvalidArgumentException stating that the driver [] (empty) is not supported is a classic symptom of a configuration mismatch, specifically where Laravel tries to access a disk defined by a string key but cannot resolve it to a valid configuration array. In your specific case involving Backpack for Laravel and custom image storage, the root cause lies in how you are referencing the disk versus how it is defined in config/filesystems.php.
You have defined a disk named 'uploads' in your configuration with a driver set to 'local' and a root pointing to public_path('uploads'). However, your model mutator attempts to use \Storage::disk($disk) where $disk is the string "public_folder".
Laravel's filesystem manager looks for a key matching that string in the disks array. Since 'public_folder' does not exist in your filesystems.php, and the default disk is named 'local', Laravel throws this error when it fails to find a mapping for the requested name. The empty brackets [] in the error message confirm that the lookup returned null or failed entirely, leaving the driver string empty.
To fix this, you must ensure the variable $disk holds a key that exists in your filesystems.php. If you intend to store files in public/uploads/images, your configuration should define a disk named exactly "public_folder" (or whatever name you choose) and point it to the correct path.
Here is the corrected configuration for your config/filesystems.php:
'uploads' => [
'driver' => 'local',
'root' => public_path('uploads'), // Matches your physical folder
],
// ... other disks
And update your model mutator to reference the key defined above:
public function setImageAttribute($value)
{
$attribute_name = "image";
// Ensure this string matches a key in config/filesystems.php
$disk = "uploads";
$destination_path = "images";
if ($value === null) {
\Storage::disk($disk)->delete($this->image);
$this->attributes[$attribute_name] = null;
}
if (str_starts_with($value, 'data:image')) {
$image = \Image::make($value);
$filename = md5($value . time()) . '.jpg';
// Store on disk
\Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
// Save relative path to DB.
// Note: If using public_path() in config root, you usually store just the filename
// or a path relative to storage/app/public depending on visibility settings.
$this->attributes[$attribute_name] = $destination_path.'/'.$filename;
}
}
The Backpack Context
You mentioned using Backpack for Laravel. While Backpack provides convenient CRUD fields, it does not automatically configure your storage disks. It relies entirely on your config/filesystems.php. When you define a field with 'upload' => true, Backpack generates the upload logic but expects the disk to be pre-configured. If the configuration is missing or misspelled, the framework throws the generic exception before even attempting the upload logic.
Visibility and Synchronization
A subtle pitfall in your setup involves the visibility setting in config/filesystems.php. You defined the 'uploads' disk without a visibility flag. By default, local disks are private (stored in storage/app). If you want users to access these images directly via a web browser at yoursite.com/uploads/images/..., that path must be symlinked or mounted.
In Laravel Homestead (and standard Laravel installations), the convention is:
- Define the disk pointing to
public_path('uploads')with'visibility' => 'public'. - Ensure
public/uploadsis accessible from your web server root.
If you define the disk as:
'root' => storage_path('app/public/uploads'), // Using storage_path instead of public_path
You do not need to set visibility to public, but you must ensure the symbolic link exists between storage/app/public and your web server root. However, using public_path() in the config is generally safer for development on Homestead unless you have specific symlink requirements.
Best Practices for Mutators
Your current mutator logic is functional once the disk name is corrected. However, be aware that Backpack often handles image uploads differently depending on whether the field is a simple string or a collection. If your Project model expects a single path string but Backpack sends an array of files (or vice versa), you might encounter further type errors.
Additionally, ensure that your storage/app/public folder is symlinked to public/storage if you are relying on the standard Laravel asset pipeline, or adjust your paths accordingly. For Homestead specifically, verify that the folders have the correct permissions (chmod -R 755 storage bootstrap/cache) so the web server user can write files there.
By aligning the disk key in your mutator with the keys defined in filesystems.php and ensuring the path visibility matches your deployment strategy, the Driver [] is not supported error will resolve itself.