ホーム > Laravel > 【Laravel】How to Fix Filesystem::has(): Argument #1 ($location) must be of type string, null given
Laravel

【Laravel】How to Fix Filesystem::has(): Argument #1 ($location) must be of type string, null given

Thank you for your continued support.
This article contains advertisements that help fund our operations.

Table Of Contents

  1. Solution

I have summarized how to resolve the following error:

League\Flysystem\Filesystem::has(): Argument #1 ($location) must be of type string, null given

Solution

The error message itself was not immediately clear, but the issue was caused by the exists method in the following code:

$isFile = Storage::disk('s3')->exists($url); // Error occurs if $url is null

This started happening after upgrading a project originally developed in Laravel 5 or 6 to Laravel 10.

Previously, when exists() received null, it would return false without any issues. However, it seems that now it only accepts a string, and null is no longer allowed (though I am not sure of the exact change).

You can fix this by wrapping it with an if statement like this:

$isFile = false;
if($url){
    $isFile = Storage::disk('s3')->exists($url);
}

I hope this helps someone.

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!