Laravel 读取 json 文件
hefengbao 发布于 2024.08.26
假设 json 文件存放在 storage/app/
目录下:
方法一:
use Illuminate\Support\Facades\File;
$contents = File::get(Storage::path('product.json'));
$arr = json_decode($contents, true);
方法二:
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
$arr = File::json(Storage::path('product.json'), true);
方法三:
use Illuminate\Support\Facades\Storage;
$arr = Storage::json('product.json');
参考:
https://www.laravelia.com/post/how-to-read-json-file-in-laravel-10
有 0 条评论
发表评论
您的电子邮箱地址不会被公开。 必填项已用 * 标注