easy-slug / easy-slug
Laravel Package for creating a slug
Installs: 16 016
Dependents: 1
Suggesters: 0
Security: 0
Stars: 18
Watchers: 1
Forks: 5
Open Issues: 3
Requires
- php: >=5.4.0
- phpunit/phpunit: ^4.7
Requires (Dev)
- mockery/mockery: 0.9.*
README
Quick start
EasySlug provides a flexible way to create slugs. It is compatible with both Laravel4 as well as Laravel5
Installation
In order to install EasySlug, just add
"easy-slug/easy-slug": "2.0.*"
to your composer.json. Then run composer install
or composer update
.
Then in your config/app.php
add
'EasySlug\EasySlug\EasySlugServiceProvider',
in the providers array and
'EasySlug' => 'EasySlug\EasySlug\EasySlugFacade'
to the aliases
array.
Simple Slug with validation from database
You can make a simple slug with DB validation using following code
<?php use EasySlug\EasySlug\EasySlugFacade as EasySlug; /** * @param1 => The string to be slugged * @param2 => The table name where slug is stored * @param3 (Optional) => The column name of slug. If not specified, by default "slug" is considered * @param4 (Optional) => The separator of slug. If not specified, by default "-" is taken */ EasySlug::generateUniqueSlug('Your String', 'table name', $column = "slug", $separator = '-')
This function looks for similar slugs in the table/column name specified in parameters. If slugs with similar pattern are found it appends numeric digits at the end of slug as follows :
your-string
your-string-2
your-string-3
your-string-4
Simple Slug without database validation
You can also make a simple slug with string as a input
<?php use EasySlug\EasySlug\EasySlugFacade as EasySlug; EasySlug::generateSlug('Your String', $separator = '-')
License
EasySlug is free software distributed under the terms of the MIT license