I am attempting to create an action that can both be run against a whole resource (standalone) and selected resources, is this possible or will I need two separate actions?
If I register the action as standalone it still appears on the detail view but does nothing when I run it.
I have attempted the following in the handle function but it won't work as I am assuming if you set the action as standalone it doesn't get the models collection.
public function handle(ActionFields $fields, Collection $models)
{
if ($models->isEmpty())
$models = Customer::withOutstandingBalance()->get();
foreach($models as $customer)
{
Mail::to('[email protected]')->send(new CustomerChaseOutstanding($customer));
}
}
If you have an action that does not require any resources / models to run, you may register it as a "standalone" action by chaining the standalone method when registering the action. This action always receives an empty collection of models in its handle method:
So the collection should be empty in this case. I would either expect that your query to retrieve the models is returning nothing or some error is thrown somewhere.
You can inspect the network requests in your browser and see if the ajax request for the action is working or not.