Skip to content

Instantly share code, notes, and snippets.

@mul14
Created September 12, 2014 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mul14/ab5f96264360f383dfa1 to your computer and use it in GitHub Desktop.
Save mul14/ab5f96264360f383dfa1 to your computer and use it in GitHub Desktop.
Laravel - Automatic create slug when saving
<?php namespace App;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
class Article extends Model {
public function setSlugAttribute($value)
{
$this->attributes['slug'] = Str::slug($value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment