The file facade simply contains some primitive methods that work only with an absolute path or relative to your script:
\File::makeDirectory('/home/www/myProject/storage/app/uploads/14214');\File::copy('/home/www/myProject/storage/app/uploads/14214/test.json', '/home/www/myProject/storage/app/uploads/99999/test.json');
Storage Facade contains a set of complex methods and is a wrapper for other third-party tools.
The first advantage is that you can use the relative folder path:
Storage::makeDirectory('uploads/14214');Storage::copy('uploads/14214/test.json', 'uploads/99999/test.json');
You can change the default folder /storage/app in config/filesystems.php or create other disks that you can call using Storage::disk('specialxyz')->copy(...) .
You can also save raw file contents to a file as follows:
Storage::put('file.jpg', $contents);
And my favorite, it is very easy to upload custom files using
$path = Storage::putFile('avatars', $request->file('avatar'));
or
$path = $request->file('avatar')->store('avatars');
By default, the store method generates a unique identifier as a file name. The file extension will be determined by examining the MIME file type. The file path will be returned by the store method so that you can save the path, including the generated file name, in your database.
Adam
source share