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.
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()
);
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',
],
],
'source' => [
'default' => [
'connection' => 'mysql',
'model' => User::class,
'relationships' => [
'mainProfile',
],
],
],
];
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.