laravel/framework · error · InvalidArgumentException
Unknown visibility: .
Error message
Unknown visibility: {$visibility}. What it means
Thrown by FilesystemAdapter::parseVisibility() when $visibility is non-null and does not match FilesystemContract::VISIBILITY_PUBLIC ('public') or VISIBILITY_PRIVATE ('private'). The match expression maps those two constants to league/flysystem Visibility enum values; anything else is rejected before reaching the adapter.
Solutions
- Pass only 'public' or 'private' (the exact string constants).
- Validate user-supplied visibility against an allow-list before calling.
- Pass null to let the disk use its configured default visibility.
- Reference FilesystemContract::VISIBILITY_PUBLIC / VISIBILITY_PRIVATE to avoid magic strings.
Example fix
// before
Storage::setVisibility($path, $request->input('visibility'));
// after
$visibility = in_array($request->input('visibility'), ['public','private'], true)
? $request->input('visibility')
: null;
Storage::setVisibility($path, $visibility); Defensive patterns
Strategy: validation
Validate before calling
if (! in_array($visibility, ['public','private', null], true)) {
throw new InvalidArgumentException('Visibility must be public, private, or null.');
}
Storage::setVisibility($path, $visibility); Type guard
function isValidVisibility(?string $visibility): bool {
return in_array($visibility, ['public','private', null], true);
} Try / catch
try {
Storage::setVisibility($path, $visibility);
} catch (\InvalidArgumentException $e) {
Storage::setVisibility($path, null); // disk default
} Prevention
- Use FilesystemContract::VISIBILITY_PUBLIC / VISIBILITY_PRIVATE constants.
- Validate request input against ['public','private'] before passing.
- Pass null to accept the disk default.
- Avoid case variants and synonyms like 'protected'.
When it happens
Trigger: Calling Storage::putFileAs(..., $visibility), Storage::setVisibility($path, $visibility), or any operation that forwards visibility where $visibility is e.g. 'protected', 'readonly', 'PUBLIC' (wrong case), or an empty string.
Common situations: Typos or wrong case ('Public', 'PUBLIC'); passing a value sourced from unvalidated request input; mismatched enum from another library; legacy code using 'protected'.
Related errors
- Add fillable property
- Collection given to whereAttachedTo method may not be empty.
- Collection given to whereBelongsTo method may not be empty.
- Collection given to whereMorphedTo method may not be empty.
- Collection given to whereNotMorphedTo method may not be…
AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11).
Data as JSON: /api/errors/c3ee33b97acafa11.
Report an issue: GitHub.
Appendix: source
Thrown at src/Illuminate/Filesystem/FilesystemAdapter.php:1094
/**
* Parse the given visibility value.
*
* @param string|null $visibility
* @return string|null
*
* @throws \InvalidArgumentException
*/
protected function parseVisibility($visibility)
{
if (is_null($visibility)) {
return;
}
return match ($visibility) {
FilesystemContract::VISIBILITY_PUBLIC => Visibility::PUBLIC,
FilesystemContract::VISIBILITY_PRIVATE => Visibility::PRIVATE,
default => throw new InvalidArgumentException("Unknown visibility: {$visibility}."),
};
}
/**
* Define a custom callback that generates file download responses.
*
* @param \Closure $callback
* @return void
*/
public function serveUsing(Closure $callback)
{
$this->serveCallback = $callback;
}
/**
* Define a custom temporary URL builder callback.
*
* @param \Closure $callbackView on GitHub (pinned to e0f6eb3518)