Download the PHP package fomvasss/laravel-slugmaker without Composer
On this page you can find all versions of the php package fomvasss/laravel-slugmaker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fomvasss/laravel-slugmaker
More information about fomvasss/laravel-slugmaker
Files in fomvasss/laravel-slugmaker
Package laravel-slugmaker
Short Description Generate slugs when saving Eloquent models in a separate table
License MIT
Homepage https://github.com/fomvasss/laravel-slugmaker
Informations about the package laravel-slugmaker
Generate slugs in a separate table when saving Eloquent models
This package provides a trait that will generate in a separate table a unique slug when saving any Eloquent model.
The slugs are generated with Laravels str_slug
method, whereby spaces are converted to '-'.
Installation
You can install the package via composer:
! For Laravel < v5.5
Add the ServiceProvider to the providers array in config/app.php:
Publish config file:
Publish the migration file:
and run the migration:
Usage
Configure
! Pay attention! Your model should not have a field named "slug"
Your Eloquent models should use the Fomvasss\SlugMaker\ModelHasSlug
trait.
The trait contains an method getSlugSourceFields()
that you must implement yourself.
Also the trait contains public method slug()
for relations your item-model with item-slug:
Here's an example of how to implement the trait:
Get & make slugs
You can to get slug with relation-method slug()
:
Or use next scope-methods in your models:
getSlugName()
findBySlug($slug)
findOrFailBySlug($slug)
getBySlugs(array $slugs)
getArrayIdsBySlugs(array $slugs)
makeSlug(string $str = '')
For example:
Usage function helpers:
slug_get($slug)
slug_get_models($slugs, $class = null)
slug_get_id($slug, $class = null)
slug_get_ids($slugs, $class = null)
slug_get_grouped_class($attributes)
slug_make($model, $slug = '')
// if empty $slug - generate withgetSlugSourceFields(): array
slug_delete($model)
Usage class SlugHelper:
The getIds()
return the array:
The getIdsGroupedByClass($attributes)
return the array:
Change log
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.