Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Commit 3759180

Browse files
committed
implement #3
1 parent 6d56a92 commit 3759180

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

README.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,6 @@ public function show(Post $post){
115115

116116
## Customisation
117117

118-
### Padding
119-
120-
Change the minimum length of a slug (default: 5)
121-
122-
```php
123-
class Post extends Model {
124-
use HasHashSlug;
125-
126-
protected static $minSlugLength = 10;
127-
}
128-
```
129-
130118
### Salts
131119

132120
The uniqueness of hashslug series per model and app installation depends on having unique salts.
@@ -141,7 +129,7 @@ To change the 'application salt', create file `config/hashslug.php` then add the
141129
<?php
142130

143131
return [
144-
'appsalt' => 'your-application-salt'
132+
'appsalt' => 'your-application-salt'
145133
];
146134
```
147135

@@ -153,29 +141,52 @@ To use a custom model salt instead of the classname:
153141

154142
```php
155143
class Post extends Model {
156-
use HasHashSlug;
144+
use HasHashSlug;
157145

158-
protected static $modelSalt = "posts";
146+
protected static $modelSalt = "posts";
159147
}
160148
```
161149

162150
This might be a good idea to do, if you have several extended classes of the same model and you need hashslugs to be consistent.
163151

152+
### Padding
153+
154+
Change the minimum length of a slug (default: 5)
155+
156+
```php
157+
class Post extends Model {
158+
use HasHashSlug;
159+
160+
protected static $minSlugLength = 10;
161+
}
162+
```
164163

165-
#### Alphabet
164+
You can set the minimum length of a slug globally too, by adding the following line to `config/hashslug.php`:
165+
166+
```php
167+
'minSlugLength' => 10
168+
```
169+
170+
### Alphabet
166171

167172
The default alphabet is `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`
168173

169174
This can be changed:
170175

171176
```php
172177
class Post extends Model {
173-
use HasHashSlug;
178+
use HasHashSlug;
174179

175-
protected static $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
180+
protected static $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
176181
}
177182
```
178183

184+
You can set the alphabet globally too, by adding the following line to `config/hashslug.php`:
185+
186+
```php
187+
'alphabet' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
188+
```
189+
179190
## Similar packages and how is this one different
180191

181192
#### [Laravel Hashids](https://github.com/vinkla/laravel-hashids)

src/HasHashSlug.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ trait HasHashSlug {
4444
private static function getHashids(){
4545
if (is_null(static::$hashIds)){
4646

47-
$minSlugLength = 5;
47+
$minSlugLength = config('hashslug.minSlugLength', 5);
4848
if(isset(static::$minSlugLength)) {
4949
$minSlugLength = static::$minSlugLength;
5050
}
@@ -58,7 +58,7 @@ private static function getHashids(){
5858
if(isset(static::$alphabet)) {
5959
$alphabet = static::$alphabet;
6060
}else{
61-
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
61+
$alphabet = config('hashslug.alphabet', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890');
6262
}
6363

6464
$salt = config('hashslug.appsalt', env('APP_KEY')) . $modelSalt;

0 commit comments

Comments
 (0)