A handy File method to read JSON files in Laravel 10.x
We now have a nice addition to the
File facade in Laravel 10.x that lets you read JSON files easily. Essentially, it’s a wrapper around the
json_decode() function. So, you can use it to read JSON files like so.
use Illuminate\Support\Facades\File; $users = File::json('users.json');
It saves you the extra step of using the
json_decode() function to read JSON files which you would have to do otherwise.
use Illuminate\Support\Facades\File; $users = json_decode(File::get('users.json'), true);
I really dig such small and focused methods that makes your code more readable and concise.