Text column no record(s)

$invoices = Invoice::select('id as item_id', 'invoice_to as fr_id', 'transaction_type', 'created_at', 'invoice_amount as amount', DB::raw("'invoice' as entry_type"), 'closing_balance_amount') ->where('invoice_to', 5)->get(); return $invoices->toQuery(); Above code used in getTableQuery , can we show data in Table Column using TextColumn
6 Replies
Dan Harrin
Dan Harrin2y ago
why ->toQuery() you just need to return the query builder object also ensure that the models from the query are being hydrated properly, i see that things like id as item_id will probably break that
Hemanath
HemanathOP2y ago
ok wil check .... toQuery for the returning ..we are try to acheive below code show in text column'$invoices = Invoice::select('id as item_id', 'invoice_to as fr_id', 'transaction_type', 'created_at', 'invoice_amount as amount', DB::raw("'invoice' as entry_type"), 'closing_balance_amount') ->where('invoice_to', 5); $receipts = Receipt::select('id as item_id', 'received_from as fr_id', DB::raw("'' as transaction_type"), 'created_at', 'amount as amount', DB::raw("'receipt' as entry_type"), 'closing_balance_amount') ->where('received_from', 5); $ledger = $invoices->union($receipts) ->orderBy('created_at') ->get() return $ledger->toQuery();`
Dan Harrin
Dan Harrin2y ago
im trying not to be patronising here, but do you understand what toQuery() does? also, do you understand how a relationship will make this much easier?
Hemanath
HemanathOP2y ago
return data is in Eloquent\collection for use in getTableQuery I want return data in Eloquent\Builder so I use toQuery. The both table data is same but they don't have any relation...
Dan Harrin
Dan Harrin2y ago
look, toQuery() is not what you need here to start with, you already have a query, which you then convert into a collection, which you then convert into a query again? secondly, when you use it you lose any extra joins or selects from the original query also, its so much easier to just define a relationship to access the data. or if that is really not possible, use a basic subselect, dont overwrite the entire selection array in the query
Hemanath
HemanathOP2y ago
okay...thanks for the reply i will try out.
Want results from more Discord servers?
Add your server