PHP code example of yoosuf / laravel-dataflow
1. Go to this page and download the library: Download yoosuf/laravel-dataflow library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yoosuf / laravel-dataflow example snippets
use Yoosuf\LaravelDataFlow\DataFlow;
use App\Models\User;
$runId = DataFlow::for(User::class)
->allowedFilters(['status', 'country'])
->allowedSearch(['name', 'email'])
->allowedSorts(['created_at'])
->filter(['status' => 'active'])
->search('gmail.com')
->sort('-created_at')
->export('csv')
->to('exports', 'active-users.csv')
->queue();
use Yoosuf\LaravelDataFlow\DataFlow;
use App\Models\Order;
DataFlow::forQuery(
Order::query()->whereDate('created_at', now()->subDay()->toDateString())
)
->export('ndjson')
->to('feeds', 'orders-nightly.ndjson')
->sync();
use Yoosuf\LaravelDataFlow\DataFlow;
use App\Models\Product;
DataFlow::for(Product::class)
->import('csv')
->from('imports', 'products.csv')
->map([
'sku' => 'sku',
'name' => 'name',
'price' => 'price_cents',
])
->upsertBy(['sku'])
->queue();
use Yoosuf\LaravelDataFlow\DataFlow;
use App\Models\Customer;
DataFlow::for(Customer::class)
->import('csv')
->from('imports', 'customers.csv')
->map([
'email' => 'email',
'name' => 'name',
'phone' => 'phone',
'country' => 'country_code',
])
->upsertBy(['email'])
->queue();
use Yoosuf\LaravelDataFlow\DataFlow;
use App\Models\Product;
DataFlow::for(Product::class)
->import('json')
->from('imports', 'catalog.json')
->map([
'sku' => 'sku',
'title' => 'name',
'price' => 'price_cents',
'is_active' => 'status',
])
->upsertBy(['sku'])
->queue();
use Yoosuf\LaravelDataFlow\DataFlow;
use App\Models\Lead;
DataFlow::for(Lead::class)
->import('ndjson')
->from('imports', 'leads.ndjson')
->map([
'external_id' => 'external_id',
'email' => 'email',
'source' => 'source',
])
->upsertBy(['external_id'])
->sync();
'exports' => [
'fallback' => [
'enabled' => true,
'default_format' => 'csv',
'format_map' => [
'xlsx' => 'csv',
'pdf' => 'csv',
],
],
],
use Yoosuf\LaravelDataFlow\DataFlow;
use App\Models\User;
$runId = DataFlow::forQuery(
User::query()->where('status', 'active')->whereHas('posts')
)
->export('csv')
->to('exports', 'active-users.csv')
->sync();
bash
php artisan vendor:publish --tag=dataflow-config