palauaandsons/nova-tags-field

Undefined property $tags when using in an action

Opened this issue · 2 comments

When I add the tag field to an action, I get the following error:

Undefined property: class@anonymous::$tags

And here's a pastebin of the error from my logs: https://pastebin.com/gefkfDU5

I'd assume this field could be used on actions as well, but any help or suggestions are appreciated :)

Hmm... the pastebin doesn't help, can you share your implementation? I really can't debug anything without code. Thanks

I'm off from work until the 21st of January, so I can't test this code and I'm flying a little blind here (I've only got a zip of my source and no environment to test with), but here's the basic steps I took:

  1. Set up the tags package as per the instructions in the README. Create a tags resource with php artisan nova:resource Tag (probably not necessary, but eh)
  2. Create a new action called SetTags using php artisan nova:action SetTags
  3. Use the code below
<?php 

namespace App\Nova\Actions;

use Illuminate\Bus\Queueable;
use Laravel\Nova\Actions\Action;
use Illuminate\Support\Collection;
use Laravel\Nova\Fields\ActionFields;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

use PalauaAndSons\TagsField\Tags;

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

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
        foreach($models as $model) {
          $model->setTags($fields->tags);
        }
    }

    /**
     * Get the fields available on the action.
     *
     * @return array
     */
    public function fields()
    {
        return [
          Tags::make('Tags')
        ];
    }
}
  1. Try and run the SetTags action.

And this is where I'm flying blind. The two possible scenarios are:

  1. The "Run Action" box doesn't load at all, and you get that class@anonymous error message as a toast
    OR
  2. The "Run Action" box DOES load, but setting some tags and clicking "Run Action" produces the error as a toast.

I hope this helps!