Skip to content

How to use raw DB queries as data for a screen? #1769

Answered by tabuna
jakoubek asked this question in Q&A
Discussion options

You must be logged in to vote

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.
Since in the columns, we allow you to refer to the depth of the object using dot notation, for example:

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.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jakoubek
Comment options

Answer selected by jakoubek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants