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

bufferoverflow's avatar

Spatie Sluggable - unexpected 'SlugOptions'

I'm using the Laravel Sluggable package from Spatie. This is not the first the time i use this package and i did the same setup as always. The only thing that's different is that now i'm using php 7.4.

I can not understand why is the following returned. I'm surely defining and returning that variable and function.

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

I implemented the HasSlug trait in my Page model:

<?php

namespace App\Models;

use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use Illuminate\Database\Eloquent\Model;

class Page extends Model
{
    use HasSlug;

And defined the required abstract method:

    public function getSlugOptions() : SlugOptions
    {
        return SlugOptions::create()
            ->generateSlugsFrom('name')
            ->saveSlugsTo('slug')
            ->slugsShouldBeNoLongerThan(50);
    }

Seems like a php 7.4 related thing: github similar issue

But if I revert my php version to php 7.3, the package requires me 7.4:

    - spatie/laravel-sluggable 2.3.0 requires php ^7.4 -> your PHP version (7.3.12) does not satisfy that requirement.
0 likes
2 replies
bufferoverflow's avatar
bufferoverflow
OP
Best Answer
Level 7

Found it.

For some reason, after running valet use php, the command php -v was returning 7.4 but the phpinfo() I dumped showed that 7.3 was used.

I manually stoped 7.3 and valet started using 7.4. Error gone.

blakeyman's avatar

I had a similar issue where my PHPstorm environment was using PHP7.3 but Valet was running on 7.4.

Once my IDE used the same PHP as Valet then this error disappeared.

(I've added this as this post helped me realise and is deffo the solution!)

Please or to participate in this conversation.