All Projects → mtvs → Eloquent Hashids

mtvs / Eloquent Hashids

On-the-fly hashids for Laravel Eloquent models. (🍰 Easy & ⚡ Fast)

Projects that are alternatives of or similar to Eloquent Hashids

Eloquentfilter
An Eloquent Way To Filter Laravel Models And Their Relationships
Stars: ✭ 1,113 (+467.86%)
Mutual labels:  eloquent, eloquent-models, laravel
Laravel Deletable
👾 Gracefully restrict deletion of Laravel Eloquent models
Stars: ✭ 137 (-30.1%)
Mutual labels:  eloquent, eloquent-models, laravel
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+21.43%)
Mutual labels:  eloquent, eloquent-models, laravel
Laravel Nullable Fields
Handles saving empty fields as null for Eloquent models
Stars: ✭ 88 (-55.1%)
Mutual labels:  eloquent, eloquent-models, laravel
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (-60.2%)
Mutual labels:  eloquent, eloquent-models, laravel
Elasticquent
Maps Laravel Eloquent models to Elasticsearch types
Stars: ✭ 1,172 (+497.96%)
Mutual labels:  eloquent, eloquent-models, laravel
Laravel Cascade Soft Deletes
Cascading deletes for Eloquent models that implement soft deletes
Stars: ✭ 498 (+154.08%)
Mutual labels:  eloquent, eloquent-models, laravel
Laravel Lucene Search
Laravel 4.2, 5.* package for full-text search over Eloquent models based on ZF2 Lucene.
Stars: ✭ 75 (-61.73%)
Mutual labels:  eloquent, eloquent-models, laravel
Eloquent Approval
Approval process for Laravel Eloquent models
Stars: ✭ 79 (-59.69%)
Mutual labels:  eloquent, eloquent-models, laravel
Searchable
Search/filter functionality for Laravel's Eloquent models
Stars: ✭ 113 (-42.35%)
Mutual labels:  eloquent, eloquent-models, laravel
Laravel Hashids
A Hashids bridge for Laravel
Stars: ✭ 1,714 (+774.49%)
Mutual labels:  hashids, laravel
Larapoll
A Laravel package to manage your polls
Stars: ✭ 189 (-3.57%)
Mutual labels:  eloquent, laravel
Querybuilderparser
A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.
Stars: ✭ 126 (-35.71%)
Mutual labels:  eloquent, laravel
Sieve
A simple, clean and elegant way to filter Eloquent models.
Stars: ✭ 123 (-37.24%)
Mutual labels:  eloquent, laravel
Laravel Hashslug
Package providing a trait to use Hashids on a model
Stars: ✭ 136 (-30.61%)
Mutual labels:  hashids, laravel
Eager Load Pivot Relations
Eager load pivot relations for Laravel Eloquent's BelongsToMany relation.
Stars: ✭ 134 (-31.63%)
Mutual labels:  eloquent, laravel
Cms
Multilingual PHP CMS built with Laravel and bootstrap
Stars: ✭ 2,342 (+1094.9%)
Mutual labels:  eloquent, laravel
Guardian
Eloquent Guardian is a simple permissions system for your users. While there are many other packages for permissions, this one solves everything in the most eloquent way.
Stars: ✭ 121 (-38.27%)
Mutual labels:  eloquent, laravel
Laravel Model Expires
A package to assign expiration dates to Eloquent models.
Stars: ✭ 148 (-24.49%)
Mutual labels:  eloquent, laravel
Pinatra
A PHP copy of Sinatra: a DSL for quickly creating web applications in PHP with minimal effort.
Stars: ✭ 151 (-22.96%)
Mutual labels:  eloquent, laravel

Using hashids instead of integer ids in urls and list items can be more appealing and clever. For more information visit hashids.org.

Eloquent-Hashids Build Status

This adds hashids to Laravel Eloquent models by encoding/decoding them on the fly rather than persisting them in the database. So no need for another database column and also higher performance by using primary keys in queries.

Features include:

  • Generating hashids for models
  • Resloving hashids to models
  • Ability to customize hashid settings for each model
  • Route binding with hashids (optional)

Installation

$ composer require mtvs/eloquent-hashids

Setup

Base features are provided by using HasHashid trait then route binding with hashids can be added by using HashidRouting.

use Illuminate\Database\Eloquent\Model;
use Mtvs\EloquentHashids\HasHashid;
use Mtvs\EloquentHashids\HashidRouting;

Class Item extends Model
{
	use HasHashid, HashidRouting;
}

Custom Hashid Settings

It's possible to customize hashids settings for each model by overwriting getHashidsConnection(). It must return the name of a connection of vinkla/hashids that provides the desired settings.

Usage

Basics

// Generating the model hashid based on its key
$item->hashid();

// Equivalent to the above but with the attribute style
$item->hashid;

// Finding a model based on the provided hashid or
// returning null on failure
Item::findByHashid($hashid);

// Finding a model based on the provided hashid or
// throwing a ModelNotFoundException on failure
Item::findByHashidOrFail($hashid);

// Decoding a hashid to its equivalent id 
$item->hashidToId($hashid);

// Encoding an id to its equivalent hashid
$item->idToHashid($id);

// Getting the name of the hashid connection
$item->getHashidsConnection();

Add the hashid to the serialized model

Set it as default:

use Illuminate\Database\Eloquent\Model;
use Mtvs\EloquentHashids\HasHashid;

class Item extends Model
{
    use HasHashid;
    
    /**
     * The accessors to append to the model's array form.
     *
     * @var array
     */
    protected $appends = ['hashid'];
}

or specify it specificly:

return $item->append('hashid')->toJson();

Route Binding

When HashidRouting trait is used, base getRouteKey() and resolveRouteBinding() are overwritten to use hashids as route keys.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].