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

Commit bc66a9c

Browse files
authored
Update README.md
explicit binding + versions
1 parent 71f2f39 commit bc66a9c

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ However, although hashslug encoding depends on the app key, it cannot be exposed
3030
composer require balping/laravel-hashslug
3131
```
3232

33+
### Versions
34+
35+
| Laravel | Hashslug |
36+
|---------|----------|
37+
| 5.4.\* | 1.0.\* |
38+
| 5.5.\* | 1.1.\* |
39+
40+
3341
## Usage
3442

3543
Include trait on a model that you wish to have hashid slugs to hide numeric incremental ids.
@@ -40,7 +48,7 @@ use Illuminate\Database\Eloquent\Model;
4048
use Balping\HashSlug\HasHashSlug;
4149

4250
class Post extends Model {
43-
use HasHashSlug;
51+
use HasHashSlug;
4452
}
4553
```
4654

@@ -66,9 +74,9 @@ Then you can resolve the model by the slug.
6674
// app/Http/Controllers/PostController.php
6775

6876
public function show($slug){
69-
$post = Post:findBySlugOrFail($slug);
77+
$post = Post:findBySlugOrFail($slug);
7078

71-
return view('post.show', compact('post'));
79+
return view('post.show', compact('post'));
7280
}
7381
```
7482

@@ -77,10 +85,31 @@ You can use [implicit model binding](https://laravel.com/docs/master/routing#imp
7785
Just typehint models and they are automatically resolved:
7886

7987
```php
88+
// routes/web.php
89+
Route::resource('/posts', 'PostController');
90+
8091
// app/Http/Controllers/PostController.php
92+
public function show(Post $post){
93+
return view('post.show', compact('post'));
94+
}
95+
```
8196

97+
If you need [explicit model binding](https://laravel.com/docs/master/routing#explicit-binding), that's also convenient:
98+
99+
```php
100+
//app/Providers/RouteServiceProvider.php
101+
public function boot(){
102+
parent::boot();
103+
104+
Route::model('article', App\Post::class);
105+
}
106+
107+
// routes/web.php
108+
Route::resource('/articles', 'PostController');
109+
110+
// app/Http/Controllers/PostController.php
82111
public function show(Post $post){
83-
return view('post.show', compact('post'));
112+
return view('post.show', compact('post'));
84113
}
85114
```
86115

0 commit comments

Comments
 (0)