Downloads
Stars
Version
[ru] Простое создание уникального слага для Ларавел 5+
[en] Simple creation of a unique slug for Laravel 5+
composer require daaner/easy-slug
[ru]
use EasySlug\EasySlug;
use EasySlug;
[en]
use EasySlug\EasySlug;
use EasySlug;
...
use EasySlug\EasySlug;
class BaseModel extends Model
{
use EasySlug;
...
[ru]
$value
- наше значениеslug
- поле, в котором хранится наш слагcustom_field
- поле из которого будет формироваться слагЗЫ: Если Вы хотите формировать слаг из полей title
или name
- третий параметр можно не указывать (если находит title
формирует сперва из него, если нет - ищет name
). Если третий параметр не указан или не найден - формируется слаг 'slug_'. date("Y-m-d-H-i-s")
, проверяется на уникальность и, если есть совпадения, дописывает первое уникальное число через дефис.
[en]
$value
is our valueslug
is the field in which our slug is storedcustom_field
is the field from which the slug will be formedPS: If you want to form a slug from the title
or name
fields - the third parameter can be null (if it finds title
forms first of it, if not, it searches for name
). If the third parameter is not specified or not found, the slug formed 'slug_'. date("Y-m-d-H-i-s")
, is checked for uniqueness and, if there are matches, appends the first unique number with a hyphen.
public function setSlugAttribute($value) {
$this->EasySlugCheck($value, 'slug', 'custom_field');
}
https://t.me/neodaan по всем вопросам
EasySlug is open-sourced software licensed under the MIT license.