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

Smashing's avatar

Get current resourceId inside Actions

Hi,

Is there a way to get the current resourceId when I'm trying to perform an action inside handle() method, because if I'm trying to get it like in a nova Resource adding the Request class and passing it like a param inside the method i get an error
0 likes
7 replies
aurawindsurfing's avatar

Hey @smashing

Resource is passed to action as a collection, you can see it in the definition of handle() method. You should do something like:

public function handle(ActionFields $fields, Collection $models)
    {
        $model = $models->first();

Hope it helps!

Smashing's avatar

Hey @aurawindsurfing,

It helps kind of but the thing is i need the id lets say "tag" i assign something throw an action, if i'm using first() method it will give me the first tag that i have but i need every time the tag ID that i'm doing an action

Smashing's avatar

I'm trying to say that every time a do an action I need the ID of the resource i'm doing it because i wanna insert it in other table, but i'm not sure how can i get it

Smashing's avatar

public function fields(Request $request) { //select all products attached to a tag $tags = \App\Tag::where('id', $request->resourceId)->get();

 }

something like that

aurawindsurfing's avatar
Level 50

If you need all the resources then:

$models

is your answer.

$models are your $tags already, no need to rerun database query. Depending how many you will mark in nova that many you will get in the $models collection.

Smashing's avatar

Oh, yes you are right !

Thank You !

1 like
Smashing's avatar

How can I make each record on it's own row if i have a multiple select options that can be submitted at ones?

Please or to participate in this conversation.