Actually, the public directory is the only accessible directory in your application, so you shouldn't store private files there. Instead, you can check the available disks in your config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'serve' => true,
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
],
The public disk can be accessed through the browser, while local disk remains private.
Check out this example:
use Illuminate\Support\Facades\Storage;
Storage::disk('local')->move(
from: $source,
to: $dest
);
For more check out Laravel doc. https://laravel.com/docs/11.x/filesystem