Skip to content
This repository has been archived by the owner on Dec 29, 2024. It is now read-only.

Commit

Permalink
Update readme.md (#4)
Browse files Browse the repository at this point in the history
Propose a few suggestions for the readme
  • Loading branch information
Yazan-Stash authored and erashdan committed Jan 17, 2019
1 parent aa2f678 commit cc9bc8d
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* [Credits](#credits)
* [Todo](#todo)

This package make the primary key in eloquent is hashed.
This package hashes the primary key of an eloquent record.

```php
// Get Hash ID
Expand All @@ -23,34 +23,35 @@ You can install the package via composer:
composer require erashdan/hashid
```

The service provider will automatically get registered package.
Laravel's package auto discovery will automatically register the service provider for you.

You should set configuration by publish it to your project:
Then you need to publish the configuration to your project:

```bash
php artisan vendor:publish --provider="Erashdan\Hashid\HashidServiceProvider" --tag="config"
```

Then add in .env file
And add the key used for the hashing in .env file
```dotenv
HASHID_KEY=SET_YOUR_KEY
```

**OR**

Change in `config/hashid.php` key parameter to laravel application key
Use Laravel's own app key, change the _key_ parameter in `config/hashid.php` to Laravel's application key
```php
'key' => env('APP_KEY'),
```

You can change hashing length from `.env` file .
You can also change the length of the resulted hash from `.env` file.

```dotenv
HASHID_LENGTH=6
```

## Usage

The eloquent by default will not implement hashid, so you should use it as trait.
Eloquent by default doesn't implement hashid, so you should use the trait provided from the package.

```php
use Illuminate\Database\Eloquent\Model;
Expand All @@ -61,14 +62,14 @@ class Post extends Model
use Hashid;
```

After use trait in eloquent you can call hashed_id attribute.
You can then use the hashed_id attribute on the eloquent object itself.

```php
$post = \App\Post::first();
$post->hashed_id; //x7LR5oQJleJX60yPpNWV
```

To search for hashed element
Or find a resource by hash
```php
$post = \App\Post::FindOrFailHashed('x7LR5oQJleJX60yPpNWV');
$post->id; //1
Expand All @@ -89,4 +90,4 @@ composer test
- [] Create command for key generater.
- [] Can store hash id on database.
- [] Can be cached.
```
```

0 comments on commit cc9bc8d

Please sign in to comment.