You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+187Lines changed: 187 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,10 @@ Migrate The database tables
21
21
```bash
22
22
php artisan migrate
23
23
```
24
+
It will migrate `tags` , `taggables` tables
24
25
25
26
#### Setup your models
27
+
To creat a many to many polymorphic relation with your model and tags you need to use the `Taggify` trait.
26
28
```php
27
29
<?php
28
30
@@ -40,7 +42,192 @@ class Post extends Model
40
42
];
41
43
}
42
44
```
45
+
#### Usage
46
+
To attach/create new tags it uses addTags method. This method takes an array containing models or id or name of the tags you want to attach to your model and of course you can all use combination of these.
$post->addTags( [ $tag, 8, 9, 'Java']); // Tag model/ids/name
64
+
65
+
```
66
+
The name will generate a unique slug for the tag and will increment the `count` column. The `count` column will represent how many times the tag's being used.
67
+
68
+
#### Detaching given tags
69
+
70
+
```php
71
+
<?php
72
+
73
+
$post = \App\Post::findOrFail(2);
74
+
$tag = Tag::findOrFail(7);
75
+
$post->removeTags([ $tag, 8, 9, 'Java']);
76
+
77
+
```
78
+
The remove tags will detach the given tags and decrement the `count` column.
79
+
80
+
#### Detaching all tags
43
81
82
+
```php
83
+
<?php
84
+
85
+
$post = \App\Post::findOrFail(2);
86
+
$post->removeAllTags();
87
+
88
+
```
89
+
It will detach all the tags associated with the model and decrement the `count` column.
90
+
91
+
#### Re tag
92
+
93
+
```php
94
+
<?php
95
+
96
+
$post = \App\Post::findOrFail(2);
97
+
$post->reTag(['Python','PHP','php oop']);
98
+
99
+
```
100
+
It will detach Previous Tags and attach Given Tags and decrement the `count` column.
0 commit comments