Skip to content

Commit aca7331

Browse files
committed
Issue #178
1 parent 24d9b5a commit aca7331

File tree

6 files changed

+26
-8
lines changed

6 files changed

+26
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Laravel Taggable Trait
77
[![Build Status](https://travis-ci.org/rtconner/laravel-tagging.svg?branch=laravel-7)](https://travis-ci.org/rtconner/laravel-tagging)
88
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/rtconner/laravel-tagging/badges/quality-score.png?b=laravel-7)](https://scrutinizer-ci.com/g/rtconner/laravel-tagging/?branch=laravel-7)
99

10+
11+
1012
This package is not meant to handle javascript or html in any way. This package handles database storage and read/writes only.
1113

1214
There are no real limits on what characters can be used in a tag. It uses a slug transform to determine if two tags are identical ("sugar-free" and "Sugar Free" would be treated as the same tag). Tag display names are run through Str::title()

config/tagging.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
// Delimiter used within tags
2727
'delimiter' => '-',
28-
29-
// Model to use for the relation between tags and tagged records
28+
29+
'tag_model' => '\Conner\Tagging\Model\Tag',
30+
3031
'tagged_model' => '\Conner\Tagging\Model\Tagged',
32+
33+
'tag_group_model' => '\Conner\Tagging\Model\TagGroup',
3134
];

src/Console/Commands/GenerateTagGroup.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Conner\Tagging\Console\Commands;
44

55
use Conner\Tagging\TaggingUtility;
6-
use Conner\Tagging\Model\TagGroup;
76
use Illuminate\Console\Command;
87
use Symfony\Component\Console\Input\InputArgument;
98

@@ -19,7 +18,7 @@ public function handle()
1918
{
2019
$groupName = $this->argument('group');
2120

22-
$tagGroup = new TagGroup();
21+
$tagGroup = new ${TaggingUtility::tagGroupModelString()};
2322
$tagGroup->name = $groupName;
2423
$tagGroup->slug = TaggingUtility::normalize($groupName);
2524

src/Model/Tag.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public function save(array $options = [])
5555
*/
5656
public function setGroup(string $group)
5757
{
58-
$tagGroup = TagGroup::query()
58+
$model = TaggingUtility::tagGroupModelString();
59+
60+
$tagGroup = $model::query()
5961
->where('slug', TaggingUtility::normalize($group))
6062
->first();
6163

@@ -100,7 +102,7 @@ public function isInGroup($groupName): bool
100102
*/
101103
public function group()
102104
{
103-
return $this->belongsTo(TagGroup::class, 'tag_group_id');
105+
return $this->belongsTo(TaggingUtility::tagGroupModelString(), 'tag_group_id');
104106
}
105107

106108
/**

src/TaggingUtility.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,14 @@ public static function tagModelString()
266266
*/
267267
public static function taggedModelString()
268268
{
269-
return config('tagging.tagged_model', 'Conner\Tagging\Model\Tagged');
269+
return config('tagging.tagged_model', '\Conner\Tagging\Model\Tagged');
270+
}
271+
272+
/**
273+
* @return string
274+
*/
275+
public static function tagGroupModelString()
276+
{
277+
return config('tagging.tag_group_model', '\Conner\Tagging\Model\TagGroup');
270278
}
271279
}

tests/TagGroupBaseTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Conner\Tagging\Model\Tag;
66
use Conner\Tagging\Model\TagGroup;
7+
use Conner\Tagging\TaggingUtility;
78

89
class TagGroupBaseTest extends BaseTestCase
910
{
@@ -91,7 +92,10 @@ private function createTagGroup($name = null): TagGroup
9192
if(is_null($name)) {
9293
$name = $this->faker->name;
9394
}
94-
return TagGroup::create([
95+
96+
$model = TaggingUtility::tagGroupModelString();
97+
98+
return $model::create([
9599
'name' => $name
96100
]);
97101
}

0 commit comments

Comments
 (0)