Package Data | |
---|---|
Maintainer Username: | faulker |
Maintainer Contact: | winter@faulk.me (Winter Faulk) |
Package Create Date: | 2017-01-28 |
Package Last Update: | 2018-04-29 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-01-24 15:02:39 |
Package Statistics | |
---|---|
Total Downloads: | 11,737 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 2 |
Total Forks: | 2 |
Total Open Issues: | 0 |
Give the ability to build profiles/configurations to be used by a artisan command to export data from the database using Eloquent models.
This has only been tested on Laravel 5.1 but it should work on higher versions
Add the fallowing to your composer.json
{
"require": {
"faulker/eloquent-export": "dev-master"
}
}
Add the service provider to config/app.php
Faulker\EloquentExport\EloquentExportServiceProvider::class,
Publish the default config file config/eloquent-export.php
php artisan vender:publish
Laravel 5.1 dosen't support the ability of getting a list of a Model's casted columns so you will have to add the Faulker\EloquentExport\EloquentExportTrait
trait to any Model that has JSON
or array
casted columns.
use Faulker\EloquentExport\EloquentExportTrait;
class MyModel extends Models
{
use EloquentExportTrait;
...
}
'profile_name' => [
'model' => \Name\Space\Root\Model::class,
'relations' => [
'[relation]' => \Name\Space\Relation\Model::class,
'[relation].[child_relation]' => \Name\Space\ChildRelation\Model::class,
],
],
Example
'user_posts' => [
'model' => \Name\Space\EloquentUser::class, // User model (root model)
'relations' => [
'posts' => \Name\Space\Posts::class, // Posts model
'posts.comment' => \Name\Space\Comments::class, // Comments model
],
],
The above profile will export a user, all their posts, and all comments for each post.
php artisan export:eloquent [profile] [path_to_file] [--id=] [--import]
config/eloquent-export.php
file.Export using the user_posts
profile:
php artisan export:eloquent user_posts /tmp/export/user_posts.json --id=34342
Import using the user_posts
profile:
php artisan export:eloquent user_posts /tmp/export/user_posts.json --import