Skip to content

Commit

Permalink
Made the slug field accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyleeh committed Nov 29, 2022
1 parent 8a03791 commit 12875f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "umomega/tags",
"description": "Tags Scaffold For umΩ Apps",
"keywords": ["umomega", "laravel", "tags", "php"],
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",
"authors": [
{
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Requests/UpdateTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function rules()
return [
'name' => 'required|array|min:1',
'name.*' => 'required|max:255',
'slug' => 'nullable|array|min:1',
'slug.*' => 'nullable|max:255',
'type' => 'nullable|max:255'
];
}
Expand Down
16 changes: 16 additions & 0 deletions src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@
namespace Umomega\Tags;

use Spatie\Tags\Tag as BaseTag;
use Illuminate\Database\Eloquent\Model;

class Tag extends BaseTag {

/**
* Override from trait
*/
public static function bootHasSlug()
{
static::saving(function (Model $model) {
collect($model->getTranslatedLocales('name'))
->each(function (string $locale) use ($model) {
if(empty($model->getTranslation('slug', $locale, false))) {
$model->setTranslation('slug', $locale, $model->generateSlug($locale));
}
});
});
}

/**
* The accessors to append to the model's array form.
*
Expand Down

0 comments on commit 12875f4

Please sign in to comment.