Laravel Storage 的常见用法
> php artisan tinker
>>> use Illuminate\Support\Facades\Storage;
>>> Storage::put('test.txt', 'hello');
=> true
ls storage/app/
public/ test.txt
文件默认创建在
继续在 tinker 中测试一下
>>> storage_path()
=> "/home/zhongwei/work/my_project/storage"
>>> storage_path('test.txt')
=> "/home/zhongwei/work/my_project/storage/test.txt"
>>> storage_path('app/test.txt')
=> "/home/zhongwei/work/my_project/storage/app/test.txt"
可见,应该是 storage_path('app/test.txt')
>>> Storage::delete('test.txt')
=> true
Config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Local.root 指定的即是默认路径。
>>> Storage::put('public/test.txt', 'hello');
=> true
>>> Storage::exists('public/test.txt');
=> true
>>> Storage::exists('public/test1.txt');
=> false
有话要说