mvaliolahi/smart-hash 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mvaliolahi/smart-hash

Composer 安装命令:

composer require mvaliolahi/smart-hash

包简介

Laravel Smart Hash Model id and request.

README 文档

README

What is the hashids?

Hashids is a small open-source library that generates short, unique, non-sequential ids from numbers. It converts numbers like 347 into strings like “yr8”, or array of numbers like [27, 986] into “3kTMd”.

For more information visit hashids.org.

Why we should use this library?

Your client deals with hash id, but each time your app received id or ids in the request SmartHash will decode it for you.

  • Easy to use!
  • Hidden your database ids from client.
  • Automatic encode model id for front-end and decode for back-end (Decode all id or ids requests from parameters or the body)
  • Does not need to methods like findByHashid

Installation

$ composer require mvaliolahi/smart-hash

$ php artisan vendor:publish

How to use

  1. inside your Model use SmartHash trait.
class Category extends Model
{
    use SmartHash;
}

$category->hashId()

After use SmartHash Trait, Category::first()->id will return jR not 1, You can access to original id using the $category->id() method.

  1. Inside you boot method in AppServiceProvider define your models because of route model binding:
$this->app->singleton('smart-hash', function() {
    return [
        'category' => Category::class,
        'user'     => User::class,
    ];
});

Add a new parameter to decoder lookup-table

edit config/smart-hash.php file, next step is obvious! for example, if we want to auto decode parameters like id, category_id and array parameter like ids, config is like below.

<?php

return [
    'single_parameters' => [
        'id', 
        'category_id'
    ],
    'array_parameters' => [
        'ids',
    ]
];

Manual find

$post = Post::findByHash('vm');
$post = Post::findOrFailByHash('vm');

统计信息

  • 总下载量: 59
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固