cviebrock/eloquent-taggable

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

AkramChauhan opened this issue · 5 comments

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.

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

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.

@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.

@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.

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