• Stars
    star
    1,909
  • Rank 24,286 (Top 0.5 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Hashids bridge for Laravel

hashids

Laravel Hashids

A Hashids bridge for Laravel.

// Encode integers.
Hashids::encode(4815162342);

// Decode strings.
Hashids::decode('1LLb3b4ck');

// Dependency injection example.
$hashidsManager->encode(911);

Build Status Monthly Downloads Latest Version

Installation

Require this package, with Composer, in the root directory of your project.

composer require vinkla/hashids

Configuration

Laravel Hashids requires connection configuration. To get started, you'll need to publish all vendor assets:

php artisan vendor:publish

This will create a config/hashids.php file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

Default Connection Name

This option default is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is main.

Hashids Connections

This option connections is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like.

Usage

Here you can see an example of you may use this package. Out of the box, the default adapter is main. After you enter your authentication details in the config file, it will just work:

// 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');

The manager will behave like it is a Hashids\Hashids class. If you want to call specific connections, you can do that with the connection method:

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.

If you prefer to use dependency injection over facades, then you can inject the manager:

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();

For more information on how to use the Hashids\Hashids class, check out the docs at hashids/hashids.

More Repositories

1

hashids

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
PHP
5,053
star
2

wordplate

WordPlate is a boilerplate for WordPress, built with Composer and designed with sensible defaults.
PHP
1,974
star
3

instagram

An easy-to-use and simple Instagram package
PHP
493
star
4

extended-acf

Register advanced custom fields with object oriented PHP
PHP
376
star
5

climb

A Composer version manager tool
PHP
359
star
6

laravel-translator

An Eloquent translator for Laravel
PHP
274
star
7

laravel-shield

A HTTP basic auth middleware for Laravel
PHP
228
star
8

laravel-gitlab

A GitLab bridge for Laravel
PHP
143
star
9

laravel-facebook

A Facebook bridge for Laravel
PHP
114
star
10

laravel-alert

A Bootstrap alert helper for Laravel
PHP
110
star
11

laravel-backup

A easy-to-use backup manager for Laravel
PHP
93
star
12

laravel-algolia

An Algolia bridge for Laravel
PHP
71
star
13

headache

An easy-to-swallow painkiller plugin for WordPress
PHP
71
star
14

recaptcha

An easy-to-use reCAPTCHA package
PHP
55
star
15

alfred-packagist

Alfred workflow to search for PHP packages with Packagist
JavaScript
21
star
16

base62

A reversible base62 ID obfuscator
PHP
21
star
17

local-login

Enable automatic login within a local WordPress environment
PHP
4
star
18

laravel-sqids

PHP
3
star
19

extended-api

Enhancing the WordPress REST API with advanced request and response objects. Work in progress.
PHP
3
star
20

bason

A lightweight JSON viewer extension for Chromium based browsers
JavaScript
2
star
21

salts

A salts generator for environment files in WordPlate
HTML
2
star
22

tabsli.de

Simple text slides for your browser-based presentation.
Svelte
1
star