1

I am using this package for slugs in my Laravel 5.5 app. I was upgrading from Laravel 4.2 and I followed upgrade instructions, so now I have this in my model:

public function sluggable()
{
    return [
        'slug' => [
            'source' => ['id', 'title'],
            'separator'  => '-',
        ]
    ];
}

but my models don't read id at all in the slug when creating.

Before when I'd save a model, I would have 123456-model, and now I am getting just model without prepended ID.

Does anyone know what the issue may be?

Norgul
  • 4,613
  • 13
  • 61
  • 144
  • Just to confirm, you're also using the Sluggable trait in your model? – Chris Forrence Dec 04 '17 at 13:56
  • 3
    I'd suggest looking here: https://github.com/cviebrock/eloquent-sluggable/issues/49 It looks like the slug is saved on creation, which means the ID doesn't exist yet. – aynber Dec 04 '17 at 14:01
  • That was resolved before with `resluggify()` but now that doesn't work as I am getting an error `Call to undefined method Illuminate\Database\Query\Builder::reslugify()` – Norgul Dec 05 '17 at 13:16

1 Answers1

0

I have resolved the issue by setting the slug to null and then saving the model (only after the model was already in the DB).

$model = new Model(...);
...
$model->save(); // <-- initial DB insert so that model has ID

// resluggify
$model->slug = null;
$model->save();
Norgul
  • 4,613
  • 13
  • 61
  • 144