编程

[Laravel 扩展包]导出 Eloquent 模型到 JSON 文件

472 2023-02-15 08:15:57

Laravel Model JSON 扩展包,让你可以轻松的地将Laravel 应用中的特定模型导出为 JSON 格式数据。它基于 php artisn 命令,提供了多种选项来定制导出处理方式。该扩展包可以帮你将重要的模型数据以便捷的格式导出:

php artisan model:export User
 
# Or specify the exact model location
php artisan model:export App\Models\User
 
# Exclude fields
php artisan model:export User --except-fields=id,deleted_at

该包也支持使用以下 flag 导出关联模型数据:

php artisan model:export Product \
  --with-relationships=category
 
# Like before, specify which fields to export
# on the relationship
php artisan model:export Product \
  --with-relationships=category:id,name

你也可以将 JSON 文件导入,并存储到数据库中:

php artisan model:import User path/to/Users.json

更多信息请查看 Github 仓库