From 9ac9c6f1bcd7ffdf9e692660e8ab62ce1699aeab Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Jan 2017 04:59:14 -0800 Subject: [PATCH] =?UTF-8?q?Updated=20convertUnicodeDbSlug=20to=20use=20Pat?= =?UTF-8?q?chwork=20if=20intl=20isn=E2=80=99t=20installed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/CustomField.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index dc2dee9175..0b17785c0f 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -7,7 +7,7 @@ use Watson\Validating\ValidatingTrait; use App\Http\Traits\UniqueUndeletedTrait; use ForceUTF8\Encoding; use EasySlugger\Utf8Slugger; - +use Patchwork\Utf8; class CustomField extends Model { @@ -37,7 +37,7 @@ class CustomField extends Model public static function boot() { - self::creating(function ($custom_field) + self::created(function ($custom_field) { \Log::debug("\n\nCreating Original Name: ".$custom_field->name); @@ -53,6 +53,9 @@ class CustomField extends Model $table->text($custom_field->convertUnicodeDbSlug())->nullable(); }); + $custom_field->db_column = $custom_field->convertUnicodeDbSlug(); + $custom_field->save(); + }); @@ -170,8 +173,16 @@ class CustomField extends Model public function convertUnicodeDbSlug($original = null) { $name = $original ? $original : $this->name; - $slug = '_snipeit_'.Utf8Slugger::slugify($name,'_'); - return $slug; + $id = $this->id ? $this->id : 'xx'; + + if (!function_exists('transliterator_transliterate')) { + $long_slug = str_slug('_snipeit_'.\Patchwork\Utf8::utf8_encode(trim($name)),'_'); + } else { + $long_slug = '_snipeit_'.Utf8Slugger::slugify($name,'_'); + } + + return substr($long_slug, 0, 50).'_'.$id; + }