Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Hala's avatar
Level 3

query in field

i want to make query in fields i used this but it's return fix value in resource

Number::make('Name' , function () { return \App\Tag::query()->with('questions')->count() }),

0 likes
6 replies
MichalOravec's avatar

@hala I don't know your whole code, but you propably want to get count of questions from your tag, but you need get item of tag for it.

Number::make('Name' , function () use ($tag) { 
    return $tag->questions()->count(); 
}),
Hala's avatar
Level 3

well yes ,i used this in index Query method but now i need more than relation so i can not use it , when i used this return fixed value , so i was looking how to query in fields not lens or filter

wingly's avatar

What exactly do you want to achieve ? And what's your resource like is it a Tag resource and you want to get the count of questions for each tag?

Hala's avatar
Level 3

well i need to know how many question in each tag in index page

yes i'm in Tag Resource

i used indexQuery method before and it was fine but now i have many queries to do

and i don't want to use lens or actions

wingly's avatar
wingly
Best Answer
Level 29

Is this not working ?

Number::make('Questions Count' , function ()  { 
    return $this->questions->count(); 
}),
Hala's avatar
Level 3

thank you a lot , yes it works now ,

Please or to participate in this conversation.