mtvs / eloquent-hashids Goto Github PK
View Code? Open in Web Editor NEWOn-the-fly hashids for Laravel Eloquent models. (๐ฐ Easy & โก Fast)
On-the-fly hashids for Laravel Eloquent models. (๐ฐ Easy & โก Fast)
Please update this package to support laravel 11. Thank you
Hello,
Thank you for the library, I was already using vinkla/hashids and yours so simplify.
Main issue for me to use hashid is case sensitive in database, when I have 'A4cd945a' and 'a4cd945a'. find only for 'a4cd945a' and data result show 'A4cd945a', that make me a little crazy.
So I added a little code to find the hashid with, where BINARY hashid
= 'a4cd945a'
This library have case sensitive for search the hashid?
Hi
I am using laravel 7.7.1, php 7.3.11
I have followed the instructions and installed composer eloquent-hashids module, however my ids are not getting encoded when I do a route call.
It seems I am missing something, do you have any ideas what I am missing ?
api.php is
Route::get('pages', 'PageController@index');
PageController is
class PageController extends Controller
{
public function index()
{
return Page::all();
}
Page Model is
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Mtvs\EloquentHashids\HasHashid;
use Mtvs\EloquentHashids\HashidRouting;
class Page extends Model
{
use HasHashid, HashidRouting;
...
when I call
GET http://{{api-url}}/pages
I was expecting
"id": <hashKey>,
"name": "My Page 1"
I still get the Id.
HTTP/1.1 200 OK
Date: Thu, 23 Apr 2020 00:53:50 GMT
Server: Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.3.11
Vary: Authorization
X-Powered-By: PHP/7.3.11
Cache-Control: no-cache, private
X-RateLimit-Limit: 500
X-RateLimit-Remaining: 499
Content-Length: 4241
Connection: close
Content-Type: application/json
[
{
"id": 1,
"name": "My Page 1"
I would like to add a prefix to the hashid to identify them.
For example:
Do you think it is a useful feature?
Regards.
Add the hashid as an attribute to Has Hashid
public function getHashidAttribute()
{
return $this->hashid();
}
I have generated the custom hashids of 10 digits. When i try to do the request validation it fails. Is there anything need to be done for validation.
Will this be updated to support Laravel 8? The current version requires illuminate/database 7.x, so isn't compatible with Laravel 8.x. Thanks!
Steps:
`Unsupported operand types: int - string
at vendor/hashids/hashids/src/Hashids.php:203
199โ while (\mb_strlen($ret) < $this->minHashLength) {
200โ $alphabet = $this->shuffle($alphabet, $alphabet);
201โ $ret = \mb_substr($alphabet, $halfLength) . $ret . \mb_substr($alphabet, 0, $halfLength);
202โ
โ 203โ $excess = \mb_strlen($ret) - $this->minHashLength;`
minHashLength seems to be evaluating to a string. The actual ID on the record used was (int)1
.
Hello, how are you?
First I would like to thank you for the library. I was already using vinkla/hashids
, but yours already helped to dry the code.
But a question arose as to how the $item->hashidToId($hashid);
method works, could you explain how to use it? Is it possible to use it without an instance of the model (as a helper)?
Thank you
P.S.: I was confused because of this $item->
I don't know where it is coming from or being instantiated. But I think it's from the model, right?
Please, add laravel 7 support. Currently when installing library, composer throws this error:
mtvs/eloquent-hashids v1.1.0 requires illuminate/database ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0
Looks like it should be easy to update since no major Eloquent changes in Laravel 7.
Can you update this package to support laravel 10
eloquent-hashids/src/HasHashid.php
Line 15 in d944ea8
protected $appends = ['hashid'];
Appending hashid to model raises the following exception (even simple operations like Model::find(1)
):
TypeError: Unsupported operand types: int - string
The TypeError disappears if I remove the $appends
I'm using PHP x64 8.1.4, Laravel 8.83.5
Iโm using eloquent hashids on a number of related objects, and often I am passing a related_model_id
as part of my request.
Currently Iโm only validating it as string|required
but it would be great to be able to validate that the model actually exists, like the exists:table,column
validation rule.
Is that something youโd consider adding?
Hi,
I'm new to laravel and was not able to understand from your code how I can customize some options. For example I am looking to add a padding as described here under 'Use padding to make your output ids longer'. Is it possible to do this with this extension?
Thanks,
robin
Hi
When the hash string is invalid, an InvalidArgumentException
throws via the findByHashidOrFail()
method. I think, It supposed to have a not found exception.
Is it possible to get()
from an array of hashids?
Or perhaps access the hashidToId()
method statically?
At the moment I am having to do:
$ids = [];
foreach ($hashids as $hashid) {
array_push($ids, (new Product)->hashidToId($hashid));
}
return Product::whereIn('id', $ids)->get();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.