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

CookieMonster's avatar

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

I am using spatie/laravel-sluggable package to implement slug for my thread model. Followed through the docs and installed it. As soon as I go to my threads, it throws an error:

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

From the other issue posted regarding this, it seems like it's a php compatible issue(I'm not entirely sure). I checked my php version with different ways and they are all different.

composer.json:

"require": {
        "php": "^7.4.5",
.....

}

Via command line (php -v):

PHP 7.4.8 (cli) (built: Jul  9 2020 23:43:51) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies

Via phpinfo() :

PHP Version	7.3.20

So is there something that I need to address for this issue?

0 likes
30 replies
Snapey's avatar

composer just tells you the minimum requirement, not related in any way to what you have

Your CLI is using php 7.4 but your webserver is running php 7.3 so that needs fixing, details for which can't be given without knowing the platform and what webserver you are using

anilkumarthakur60's avatar

try with this package ...thank me latter

https://github.com/cviebrock/eloquent-sluggable
tykus's avatar

As @snapey mentioned, your problem is the webserver running PHP 7.3 which does not support return type declarations such as the package is doing. You need to update the PHP version which your webserver is running.

CookieMonster's avatar

I am using laravel valet. So I have to upgrade it from there?

CookieMonster's avatar

before I upgrade, how do I verify what valet php version I am using?

tykus's avatar

You see that in phpinfo() output

tykus's avatar

Assuming you are visiting a site being served by Valet, yes.

tykus's avatar
the bottle needs the Apple Command Line Tools to be installed.
  You can install them, if desired, with:
    xcode-select --install
tykus's avatar

AFAIK that is not the case.

CookieMonster's avatar

Apparently I installed 7.4 but phpinfo still shows 7.3.20. How come?

CookieMonster's avatar

i'm guessing I need to stop the service something like:

 brew services stop php71

and then start the one I want:

 brew services stop php72

but I don't know the proper command.?

CookieMonster's avatar

So I run brew services list and it shows the issue:

Name      Status  User        Plist
dnsmasq   error   root        /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
[email protected] started   /Users/name/Library/LaunchAgents/[email protected]
nginx     error   root        /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php       stopped             
[email protected]   stopped             
[email protected]   error   root        /Library/LaunchDaemons/[email protected]

i'm not sure why it says error even though phpinfo() shows the correct version now...

CookieMonster's avatar

I did unlink but it's still showing up in the services list. Also it claims that [email protected] is started but why does the status says error?

What about nginx and dnsmasq?

tykus's avatar

Don't know... mine is the same; had never noticed before?

Is the SlugOptions error gone now?

CookieMonster's avatar

Not yet.

Mine sharing what is your brew services list?

Tried running my application normally and everything works as fine so i am not sure if I should be concerned about those issue. Or maybe I should start a new thread..

tykus's avatar

But phpinfo() says that you are using version 7.4?

Sure:

~                                                                                                                                                  ⍉
▶ brew services list
Name    Status  User Plist
dnsmasq unknown root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
mailhog stopped
nginx   unknown root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php     error   root /Library/LaunchDaemons/homebrew.mxcl.php.plist
unbound stopped
CookieMonster's avatar

Yea it shows 7.4.16. However, my composer.json shows:

"require": {
        "php": "^7.4.5",

....

How do I update it to match?

tykus's avatar

Forget about the platform dependencies, they are not relevant to this situation.

david001's avatar

@tykus I have php 7.4

Valet is already using version: [email protected]. To re-link and re-configure use the --force parameter.

I am getting similar error in browser

david001's avatar

how did you fixed this. I am getting same error. I have PHP 7.4 Valet is already using version: [email protected]. To re-link and re-configure use the --force parameter.

Thanks

Please or to participate in this conversation.