getTableQuery

Can we return array inside getTableQuery instead of model, because Iam getting data by combining three database Tables
protected function getTableQuery(): Builder { return Arr::get($this->final_result, 'result'); }
3 Replies
bwurtz999
bwurtz99915mo ago
I don't think you can return an array. But I have done something similar using custom select statements and union Example:
$table1Data = Model1::where('user_id', $something)
->select(DB::raw('custom_select_statement'));

$table2Data = Model2::where('somthing_id', $somethingElse)
->select(DB::raw('some_other_custom_select_statement'));

$union = $table1Data->union($table2Data);

return $union;
$table1Data = Model1::where('user_id', $something)
->select(DB::raw('custom_select_statement'));

$table2Data = Model2::where('somthing_id', $somethingElse)
->select(DB::raw('some_other_custom_select_statement'));

$union = $table1Data->union($table2Data);

return $union;
SQL union rules apply - so each select statement needs the same number of columns. And you will need to make sure that the columns from each select statement have similar data types The downside with this is that the model/record is whatever you have returned from the select statement, not a true instance of the model
Roshan_k
Roshan_kOP15mo ago
Thank you
waleedGRT
waleedGRT15mo ago
You can return an array using a package called "calebporzio/sushi"
Want results from more Discord servers?
Add your server