laravel hashids
7.0.0
Laravel용 Hashids 브릿지.
// Encode integers.
Hashids:: encode ( 4815162342 );
// Decode strings.
Hashids:: decode ( ' 1LLb3b4ck ' );
// Dependency injection example.
$ hashidsManager -> encode ( 911 );
프로젝트의 루트 디렉터리에 Composer와 함께 이 패키지가 필요합니다.
composer require vinkla/hashids
Laravel Hashids에는 연결 구성이 필요합니다. 시작하려면 모든 공급업체 자산을 게시해야 합니다.
php artisan vendor:publish
이렇게 하면 구성을 설정하기 위해 수정할 수 있는 config/hashids.php
파일이 앱에 생성됩니다. 또한 릴리스 간에 이 패키지의 원래 구성 파일에 대한 변경 사항을 확인하십시오.
이 옵션 default
에서는 아래 연결 중 모든 작업에 대한 기본 연결로 사용할 연결을 지정할 수 있습니다. 물론, 관리자 클래스를 사용하면 한 번에 여러 연결을 사용할 수 있습니다. 이 설정의 기본값은 main
입니다.
이 옵션 connections
애플리케이션에 대한 각 연결이 설정되는 곳입니다. 예제 구성이 포함되어 있지만 원하는 만큼 연결을 추가할 수 있습니다.
여기에서 이 패키지를 사용할 수 있는 예를 볼 수 있습니다. 기본적으로 기본 어댑터는 main
입니다. 구성 파일에 인증 세부 정보를 입력하면 다음과 같이 작동합니다.
// You can alias this in config/app.php.
use Vinkla Hashids Facades Hashids ;
// We're done here - how easy was that, it just works!
Hashids:: encode ( 4815162342 );
// This example is simple and there are far more methods available.
Hashids:: decode ( ' doyouthinkthatsairyourebreathingnow ' );
관리자는 HashidsHashids
클래스처럼 동작합니다. 특정 연결을 호출하려면 다음 연결 방법을 사용하면 됩니다.
use Vinkla Hashids Facades Hashids ;
// Writing this...
Hashids:: connection ( ' main ' )-> encode ( $ id );
// ...is identical to writing this
Hashids:: encode ( $ id );
// and is also identical to writing this.
Hashids:: connection ()-> encode ( $ id );
// This is because the main connection is configured to be the default.
Hashids:: getDefaultConnection (); // This will return main.
// We can change the default connection.
Hashids:: setDefaultConnection ( ' alternative ' ); // The default is now alternative.
Facade보다 종속성 주입을 선호하는 경우 관리자를 주입할 수 있습니다.
use Vinkla Hashids HashidsManager ;
class Foo
{
protected $ hashids ;
public function __construct ( HashidsManager $ hashids )
{
$ this -> hashids = $ hashids ;
}
public function bar ( $ id )
{
$ this -> hashids -> encode ( $ id );
}
}
App:: make ( ' Foo ' )-> bar ();
HashidsHashids
클래스를 사용하는 방법에 대한 자세한 내용은 hashids/hashids
문서를 확인하세요.