-
Hi, what is the proposed way to encapsulate the result of a raw database query (one that does NOT return an Eloquent collection, but instead an array of arrays) into a Repository? This does not work: return [
'accounts' => DB::connection('mydbconnection')
->select('SELECT id, name FROM accounts'),
]; ... since it leads to that understandable error:
Do I have to iterate over every array element and put it into an Repository? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @jakoubek. The short answer is yes: $result = DB::connection('mydbconnection')->select('SELECT id, name FROM accounts');
$accounts = collect($result)->transform(fn(array $account) => new \Orchid\Screen\Repository($account)); You may be wondering why is this needed? This is necessary to be consistent. TD::make('accounts.balance'); And other similar things. Therefore, we require that it be defined, either in the class of the array was wrapped in an object that will allow you to do this. |
Beta Was this translation helpful? Give feedback.
Hi @jakoubek. The short answer is yes:
You may be wondering why is this needed? This is necessary to be consistent.
Since in the columns, we allow you to refer to the depth of the object using dot notation, for example:
And other similar things. Therefore, we require that it be defined, either in the class of the array was wrapped in an object that will allow you to do this.