Orchid - Adjust queries to Database #1687
Unanswered
CarlsonBuma
asked this question in
Q&A
Replies: 2 comments 3 replies
-
Hello @CarlsonBuma , In your PostListScreen which has query method you should eager load authors(this will reduce amount of queries) public function query(): array
{
return [
'posts' => Post::filters()
->with('author') # You must define this relation on Post model
->paginate(),
];
} Now in your PostListLayout: class PostsListLayout extends Table
{
protected $target = 'admissions';
protected function columns(): array
{
return [
# Accessing fields on a relation with 'relation_name.attribute_name'
TD::make('author.name', 'Auhtor'),
# OR alternatively
TD::make('author_name', 'Auhtor')
->(function(Post $post) { return $post->author->name; }),
];
}
} Both work fine, though I prefer first syntax as its simple |
Beta Was this translation helpful? Give feedback.
3 replies
-
Any idea how to apply the filters and sorting for this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm kinda new in Laravel - Orchid.
So I'm not very familiar with the Framework and I couldnt found it in my Project nor in the internet research.
So I try to learn about the structure of Orchid, belonging to query building to CRUD in Database.
I currently using it as Backend Framework (admin).
I need to change a query - cause I receive a ForeignKey but I want to have the relationship to the PK.
How to Search for Table Relations?
Would also be nice, if you could include examples in your Doc, which shows the structure of your Integration & query building.
Btw. its a very nice platform! Thanks alot
Beta Was this translation helpful? Give feedback.
All reactions