2

I am developing a Admin Panel using Laravel Nova. I know Laravel Nova is a new technology. Now I am having a bit of problem using Nova actions. I need to get the number of selected entries for the action. Please see the screenshot below.

enter image description here

As you can see in the screenshot, I selected two entries for the action. In Nova action class, in fields method of action class, I'd like to get the number of selected entries.

class ActivateUsers extends Action
{
    use InteractsWithQueue, Queueable, SerializesModels;

    public function handle(ActionFields $fields, Collection $models)
    {
        foreach ($models as $model) {

        }
    }

    public function fields()
    {
         //Here I need to get the number of selected entries
    }
}

Please pay attention to the fields method of the Action and the comment in it. How can I get the number of selected entries in the fields method of the action class?

1 Answer 1

0

Try to use the operation this way:

public function handle(ActionFields $fields, Collection $models)
{
    $models->count(); // number of selected entries
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.