Join 3 tables

I want to write a query that joins 3 tables in filament that are less related
4 Replies
codeartisan
codeartisan3mo ago
$advances = DB::table('advances')
->select('amount_before', 'amount_after', 'amount', 'date')
->where('customer_id', $customerId)
->get();

$balancings = DB::table('balancings')
->select('net_pay_out', 'deductable_advance', 'price', 'date')
->where('customer_id', $customerId)
->get();

$cashPayments = DB::table('cash_payments')
->select('amount as deductable_advance', 'date') // Rename the amount field
->where('customer_id', $customerId)
->get();

// Merge the results of advances and balancings into a single collection
$ledger = $advances->merge($balancings)->merge($cashPayments);

// Sort the merged collection by the 'date' field in ascending order
$sortedLedger = $ledger->sortBy('date');

// Convert the sorted collection to a plain array for JSON response,
// and then reindex the array numerically
$ledgerArray = $sortedLedger->values()->toArray();
$advances = DB::table('advances')
->select('amount_before', 'amount_after', 'amount', 'date')
->where('customer_id', $customerId)
->get();

$balancings = DB::table('balancings')
->select('net_pay_out', 'deductable_advance', 'price', 'date')
->where('customer_id', $customerId)
->get();

$cashPayments = DB::table('cash_payments')
->select('amount as deductable_advance', 'date') // Rename the amount field
->where('customer_id', $customerId)
->get();

// Merge the results of advances and balancings into a single collection
$ledger = $advances->merge($balancings)->merge($cashPayments);

// Sort the merged collection by the 'date' field in ascending order
$sortedLedger = $ledger->sortBy('date');

// Convert the sorted collection to a plain array for JSON response,
// and then reindex the array numerically
$ledgerArray = $sortedLedger->values()->toArray();
Thats what I had before I want to convert it to filament // Return the response as JSON, with data as an array of items return response()->json(['data' => $ledgerArray]);
LeandroFerreira
LeandroFerreira3mo ago
Table Builder uses Eloquent. If you want to use a custom data, check the sushi package https://filamentphp.com/community/how-to-consume-an-external-api-with-filament-tables
Filament
How to consume an external API with Filament Tables by Leandro Ferr...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
codeartisan
codeartisan3mo ago
Thank you let me check it out