Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined property $tags when using in an action #3

Open
Grayda opened this issue Dec 14, 2018 · 2 comments
Open

Undefined property $tags when using in an action #3

Grayda opened this issue Dec 14, 2018 · 2 comments

Comments

@Grayda
Copy link

Grayda commented Dec 14, 2018

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 :)

@ipalaus
Copy link
Member

ipalaus commented Dec 18, 2018

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

@Grayda
Copy link
Author

Grayda commented Dec 19, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants