Twill: How to get tags

Created on 5 Feb 2019  路  3Comments  路  Source: area17/twill

I added HandleTags trait to repository and field to form template. The field is rendered and tags are saved. I just don't know how to actually get tags now or even better how to get all items with specific tags.

Thanks! :)

Most helpful comment

OK, never mind I figured it out 馃槃

For future self:

  1. add use HandleTags; to model repository
  2. add @formField('tags') to form.blade.php
  3. get tags with model->tags
  4. use model::withTag([]) to get all items with tags

@ifox we (I) need guides/recipies in docs so I can stop writing self-closing issues! :stuck_out_tongue: 馃槉

All 3 comments

OK, never mind I figured it out 馃槃

For future self:

  1. add use HandleTags; to model repository
  2. add @formField('tags') to form.blade.php
  3. get tags with model->tags
  4. use model::withTag([]) to get all items with tags

@ifox we (I) need guides/recipies in docs so I can stop writing self-closing issues! :stuck_out_tongue: 馃槉

Hey @zipavlin
I tried that and I just get error:
Call to a member function count() on null (View: T:\www\mm\vendor\area17\twill\views\partials\form_tags.blade.php)

As a reference for others, do NOT do any of the following as they will stop it from working and cause errors...

  • do NOT add a 'name' => 'xyz' attribute to the tag field you add to your view file.
  • do NOT start creating migrations and adding a column in your database for this field, its handled by the 'tags' tables twill creates on install.
  • do NOT add a fillable for tags inside of your model file.

I was getting the exact same error @awgul as you due to a combination of these mistakes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bastienrobert picture bastienrobert  路  7Comments

karneaud picture karneaud  路  3Comments

jayhaluska picture jayhaluska  路  4Comments

manuelsofia picture manuelsofia  路  4Comments

madsem picture madsem  路  4Comments