Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

azular23's avatar

syntax error, unexpected 'SlugOptions' in spatie/Laravel-sluggable

Hi guys, im really confused on this error

syntax error, unexpected 'SlugOptions' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)

about spatie/laravel-sluggable package. I did some couple of research and some people stated is to check the composer and php version which in my case I have the 7.4 version. This error only occurs on my dev server but it works perfectly on my local development environment and both have the same version of every packages.

composer.json

"require": {
        "php": "^7.4",
        "ext-curl": "*",
        "ext-json": "*",
        "darkaonline/l5-swagger": "^7.0",
        "doctrine/dbal": "^2.10",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^1.0",
        "guzzlehttp/guzzle": "^6.5",
        "laravel/framework": "^7.0",
        "laravel/passport": "^9.2",
        "laravel/socialite": "^5.0",
        "laravel/tinker": "^2.0",
        "laravel/ui": "^2.0",
        "laravolt/avatar": "^3.2",
        "socialiteproviders/facebook": "^1.0",
        "spatie/laravel-sluggable": "^2.5"
},

My local php version

PHP 7.4.8 (cli) (built: Jul  9 2020 11:30:39) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Server php version

PHP 7.4.10 (cli) (built: Sep  9 2020 06:36:14) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
0 likes
9 replies
Sinnbeck's avatar

Please show on what line and in what file the error occured.

And on the server, make a file in /public called phpinfo.php and paste this into it. Then call it in the browser

<?php
phpinfo();
azular23's avatar

Hi, the error occured when I used hasSlug on one of my model


use Spatie\Sluggable\SlugOptions;

class Listofgood extends Model
{
    use SoftDeletes;
    use HasSlug; <---- *Right here*

}

And on my server phpinfo my php version is 7.2.8 which is kinda weird when i try to run php -v its 7.4.10

laracoft's avatar

@azular23 it is much easier for us if you can paste the error exception output that comes built-in with Laravel.

Sinnbeck's avatar

Then you have only updated the cli version. You might need to restart the webserver if you just upgraded

If you can tell me what you are using (apache or nginx), I can tell you how

azular23's avatar

@laracoft Sorry but something like this?

ParseError
syntax error, unexpected 'SlugOptions' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) 
Sinnbeck's avatar

Well as we have already found out it is caused by php 7.2, lets focus on getting that upgraded.

And I think @laracoft meant the whole error (with line number etc)

azular23's avatar

@sinnbeck thank you for your help, I just also configure one file in my sites-available by navigating through

/etc/nginx/sites-available/

then i just changed the PHP-FPM socket inside the file located inside the location block location ~ \.php$

from

location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
}

to

location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
}

then i reload the server.

Please or to participate in this conversation.