Export Eloquent Models to JSON Files
Last updated on by Paul Redmond
Model JSON is a package that allows you to easily export data from specific Laravel Eloquent models in your Laravel application to JSON format. It is based on the php artisan command and offers various options to customize the export process. This package helps export important data from your models in a convenient format:
php artisan model:export User # Or specify the exact model locationphp artisan model:export App\Models\User # Exclude fieldsphp artisan model:export User --except-fields=id,deleted_at
This package also supports associated model data using the following flag:
php artisan model:export Product \ --with-relationships=category # Like before, specify which fields to export# on the relationshipphp artisan model:export Product \ --with-relationships=category:id,name
Lastly, you can import data from a JSON file and store it in your database:
php artisan model:import User path/to/Users.json
You can learn more about this package, get full installation instructions, and view the source code on GitHub.