naimsolong/laravel-data-extractor

A data extractor based on models and it's relationship

0.0.3 2025-07-14 01:15 UTC

This package is auto-updated.

Last update: 2025-07-14 06:19:56 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel package for extracting data from Eloquent models and their relationships with flexible configuration options. This package provides a simple and intuitive way to extract structured data from your models, making it perfect for API responses, data exports, or any scenario where you need to transform model data into a specific format.

What It Does

The extractor leverages Laravel's relationship system to automatically include related data based on your configuration, while providing fine-grained control over which fields are included or excluded from the extraction process.

You can use the available options inside config file:

use NaimSolong\DataExtractor\Extract;

// Option
(new Extract)
  ->option('User')
  ->queryId(4)
  ->toSql();

// Source
(new Extract)
  ->source('session')
  ->queryId(3)
  ->toSql();

Or you can use model that you have queried:

use NaimSolong\DataExtractor\Extract;
use App\Models\User;

// Extract directly
(new Extract)
  ->toSql(
    User::get()
  );

Installation

You can install the package via composer:

composer require naimsolong/laravel-data-extractor

You can publish the config file with:

php artisan vendor:publish --tag="data-extractor-config"

This is the contents of the published config file:

return [
    'is_enabled' => env('DATA_EXTRACTOR_ENABLED', false),

    'options' => [
        [
            'name' => 'Default',
            'description' => 'Extra all user data',
            'format' => 'sql',
            'source' => 'default',
            'export' => 'default',
        ],
    ],

    'source' => [
        'default' => [
            'connection' => 'mysql',
            'model' => User::class,
            'relationships' => [
                'mainProfile',
            ],
        ],
    ],

    'export' => [
        'default' => [
            'file_name' => 'data-extractor',
            'file_path' => 'data-extractor',
            'disk' => 'local',
        ],
    ],
];

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.