cviebrock / eloquent-taggable

Easily add the ability to tag your Eloquent models in Laravel.
MIT License
537 stars 72 forks source link

preg_split(): Compilation failed: missing terminating ] for character class at offset 2 #111

Closed AkramChauhan closed 3 years ago

AkramChauhan commented 4 years ago

I tried setting up taggable for my laravel app which using framework version 7.0

I followed steps to install package. 1) Composer require ... 2) Composer update 3) Added Configuration Files 4) Run migration files 5) I marked my model as taggable as described

but when I am trying to save tag. using $model->tag("tag1,tag2");

I am getting an error ErrorException preg_split(): Compilation failed: missing terminating ] for character class at offset 2

cviebrock\eloquent-taggable\src\Services\TagService.php:78

Any comments on this would be helpful.

Thanks.

cviebrock commented 4 years ago

What does your taggable.php config file look like? Specifically the delimiters setting.

sujancse commented 3 years ago

Clearing the config cache will solve the issue @AkramChauhan

php artisan config:clear

Actually, the issue was related to the Laravel config cache. As the config was cached the result of config('taggable.delimiters') is empty.

AkramChauhan commented 3 years ago

@sujancse Thanks for your reply. No its not. I would never create issue before trying config clear. even dumping autoload files.

This is related to PHP version some how. As I my production having 7.1.2 something.

I don't remember actual error but it was something related to ternary operators which got depreciated in that specific PHP version

Like this XX : XX : XX ? YY : YY : YY not sure but something like this.

cviebrock commented 3 years ago

@AkramChauhan I'm still waiting for you to post your actual configuration file. The code that is failing for you is:

            $array = preg_split(
                '#[' . preg_quote(config('taggable.delimiters'), '#') . ']#',
                $tags,
                null,
                PREG_SPLIT_NO_EMPTY
            );

... so it does sound like there is an issue with the taggable.delimiters option.

cviebrock commented 3 years ago

Closing due to no response. Feel free to re-open or comment if you are still having issues.