Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #276

    Hi, I have a slug column in my User model that won’t update when a user changes his name. Basically, on the create method the slug will generate a slug based on the user’s name. This works in the create method meaning a unique slug will be inserted into the database.

    However, on update method , all attributes are update except the slug. Meaning the old slug are kept even though the user’s name has changed.

    • This topic was modified 1 year, 3 months ago by jacob_smith.

    Hi, please don’t forget to set onUpdate to true on the User Model as follows:

    public function sluggable(): array
    return [
    ‘slug’ => [
    ‘source’ => ‘name’,
    ‘onUpdate’ => true

    Please check on the documentation why Sluggable won’t generate an updated slug automatically

    “By default, updating a model will not try and generate a new slug value. It is assumed that once your slug is generated, you won’t want it to change (this may be especially true if you are using slugs for URLs and don’t want to mess up your SEO mojo).”

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.