Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/larapack/attribute-slugging
Allows your Eloquent Model to automatically generate a unique slug for a attribute on save.
https://github.com/larapack/attribute-slugging
Last synced: about 2 months ago
JSON representation
Allows your Eloquent Model to automatically generate a unique slug for a attribute on save.
- Host: GitHub
- URL: https://github.com/larapack/attribute-slugging
- Owner: larapack
- License: mit
- Created: 2015-11-27T12:20:35.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-17T09:13:22.000Z (about 9 years ago)
- Last Synced: 2024-11-01T13:38:41.630Z (2 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# attribute-slugging
Allows your Eloquent Model to automatically generate a unique slug for a attribute on save.## Installing
Install using Composer `composer require larapack/attribute-slugging 1.*`.
## Usage
First add the trait `Sluggable` to your Eloquent Model.
```
'username', // set the attribute names you which to slug and from what attribute it should be generated from
];
//...
}
```Test:
```
// we make two user objects
$userA = new App\User;
$userB = new App\User;
// then we set both username's to "Mark"
$userA->username = "Mark";
$userB->username = "Mark";
// save both objects
$userA->save();
$userB->save();
// now the unique slugs have been set
echo $userA->username_slug; // outputs "mark"
echo $userB->username_slug; // outputs "mark-2"
```