@@ -30,6 +30,14 @@ However, although hashslug encoding depends on the app key, it cannot be exposed
3030composer 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
3543Include 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;
4048use Balping\HashSlug\HasHashSlug;
4149
4250class 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
6876public 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
7785Just 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
82111public function show(Post $post){
83- return view('post.show', compact('post'));
112+ return view('post.show', compact('post'));
84113}
85114```
86115
0 commit comments