Skip to content

Commit

Permalink
Issue #178
Browse files Browse the repository at this point in the history
  • Loading branch information
rtconner committed Mar 2, 2020
1 parent 24d9b5a commit aca7331
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Laravel Taggable Trait
[![Build Status](https://travis-ci.org/rtconner/laravel-tagging.svg?branch=laravel-7)](https://travis-ci.org/rtconner/laravel-tagging)
[![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)



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

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()
Expand Down
7 changes: 5 additions & 2 deletions config/tagging.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@

// Delimiter used within tags
'delimiter' => '-',

// Model to use for the relation between tags and tagged records

'tag_model' => '\Conner\Tagging\Model\Tag',

'tagged_model' => '\Conner\Tagging\Model\Tagged',

'tag_group_model' => '\Conner\Tagging\Model\TagGroup',
];
3 changes: 1 addition & 2 deletions src/Console/Commands/GenerateTagGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Conner\Tagging\Console\Commands;

use Conner\Tagging\TaggingUtility;
use Conner\Tagging\Model\TagGroup;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;

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

$tagGroup = new TagGroup();
$tagGroup = new ${TaggingUtility::tagGroupModelString()};
$tagGroup->name = $groupName;
$tagGroup->slug = TaggingUtility::normalize($groupName);

Expand Down
6 changes: 4 additions & 2 deletions src/Model/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public function save(array $options = [])
*/
public function setGroup(string $group)
{
$tagGroup = TagGroup::query()
$model = TaggingUtility::tagGroupModelString();

$tagGroup = $model::query()
->where('slug', TaggingUtility::normalize($group))
->first();

Expand Down Expand Up @@ -100,7 +102,7 @@ public function isInGroup($groupName): bool
*/
public function group()
{
return $this->belongsTo(TagGroup::class, 'tag_group_id');
return $this->belongsTo(TaggingUtility::tagGroupModelString(), 'tag_group_id');
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/TaggingUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,14 @@ public static function tagModelString()
*/
public static function taggedModelString()
{
return config('tagging.tagged_model', 'Conner\Tagging\Model\Tagged');
return config('tagging.tagged_model', '\Conner\Tagging\Model\Tagged');
}

/**
* @return string
*/
public static function tagGroupModelString()
{
return config('tagging.tag_group_model', '\Conner\Tagging\Model\TagGroup');
}
}
6 changes: 5 additions & 1 deletion tests/TagGroupBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Conner\Tagging\Model\Tag;
use Conner\Tagging\Model\TagGroup;
use Conner\Tagging\TaggingUtility;

class TagGroupBaseTest extends BaseTestCase
{
Expand Down Expand Up @@ -91,7 +92,10 @@ private function createTagGroup($name = null): TagGroup
if(is_null($name)) {
$name = $this->faker->name;
}
return TagGroup::create([

$model = TaggingUtility::tagGroupModelString();

return $model::create([
'name' => $name
]);
}
Expand Down

0 comments on commit aca7331

Please sign in to comment.