Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbedard committed Apr 19, 2017
1 parent 3312362 commit caef6aa
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 29 deletions.
3 changes: 2 additions & 1 deletion components/BlogTagSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public function onLoadPage($page = false)
$this->calculatePagination();

// Query the tag with it's posts
$this->tag = Tag::where('slug', $this->property('tag'))
$this->tag = Tag::where('name', $this->property('tag'))
->orWhere('slug', $this->property('tag'))
->with(['posts' => function($posts) {
$posts->skip($this->resultsPerPage * ($this->currentPage - 1))
->take($this->resultsPerPage);
Expand Down
36 changes: 27 additions & 9 deletions models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class Tag extends Model
/**
* @var array Fillable fields
*/
public $fillable = ['name'];
public $fillable = [
'name',
'slug',
];

/**
* @var array Validation rules
Expand All @@ -42,20 +45,35 @@ class Tag extends Model
public $customMessages = [
'name.required' => 'bedard.blogtags::lang.form.name_required',
'name.unique' => 'bedard.blogtags::lang.form.name_unique',
'name.regex' => 'bedard.blogtags::lang.form.name_invalid',
];

/**
* Convert tag names to slugs
* Before create.
*
* @return void
*/
public function beforeCreate()
{
$this->setInitialSlug();
}

/**
* Set the initial slug.
*
* @return void
*/
public function setSlugAttribute($value)
protected function setInitialSlug()
{
$newSlug = str_slug($value);
$this->attributes['slug'] = $newSlug;
$this->slug = str_slug($this->name);
}

if (empty($newSlug))
{
$this->attributes['slug'] = str_slug($this->attributes['name']);
}
/**
* Convert tag names to lower case
*/
public function setNameAttribute($value)
{
$this->attributes['name'] = mb_strtolower($value);
}

/**
Expand Down
11 changes: 0 additions & 11 deletions models/tag/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@
fields:
name:
label: Tag
span: left
type: text

slug:
label: Slug
span: right
placeholder: slug
preset:
field: name
type: slug

posts:
label: Posts
type: relation
nameFrom: title
emptyOption: No posts available.
span: auto
11 changes: 3 additions & 8 deletions updates/add_tag_slug.php → updates/add_slug_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Schema;
use October\Rain\Database\Updates\Migration;
use Bedard\BlogTags\Models\Tag;
use System\Classes\PluginManager;

class AddTagSlug extends Migration
{
Expand All @@ -15,15 +16,10 @@ public function up()

Schema::table('bedard_blogtags_tags', function($table)
{
$table->string('slug', 255);
$table->string('slug')->unique()->nullable();
});

$this->fillSlugs();

Schema::table('bedard_blogtags_tags', function($table)
{
$table->unique('slug');
});
}

public function down()
Expand All @@ -43,8 +39,7 @@ private function fillSlugs()
{
$tags = Tag::all();

foreach ($tags as $tag)
{
foreach ($tags as $tag) {
$tag->slug = str_slug($tag->name);
$tag->save();
}
Expand Down
5 changes: 5 additions & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@
- Add Hungarian translation (gergo85)
1.3.6:
- Add German translation (justb81)
1.3.7:
- Add slug field to tags (Fl0Cri)
- add_slug_column.php
1.4.0:
- !!! A slug is now created for each tag.

0 comments on commit caef6aa

Please sign in to comment.