vinkla / 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.
https://hashids.org/php
MIT License
5.28k stars 418 forks source link

Error Invalid text representation (hashids not decoding) with route in plural #192

Closed bashman closed 1 year ago

bashman commented 1 year ago

Hi.

I got this error in a table

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "WB3QyWpXnjKYkN5V4gl1G7RoL798exAvEwPzbLa0ZM6OqJ2mrX"
 (Connection: pgsql, SQL: select * from "citizenships" where "id" = WB3QyWpXnjKYkN5V4gl1G7RoL798exAvEwPzbLa0ZM6OqJ2mrX limit 1)

The configuration:

config/hashids.php

        \App\Models\Citizenship::class => [
            'salt' => 'safawe',
            'length' => 50,
            'alphabet' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
        ],

DeepinScreenshot_Seleccionar área_20230315142946

   app/Providers/RouteServiceProvider.php

        Route::bind('citizenships', function ($value, $route) { // not work in plural
            return $this->getModel(\App\Models\Citizenship::class, $value);
        });

DeepinScreenshot_Seleccionar área_20230315143301

Routes in plural: DeepinScreenshot_Seleccionar área_20230315143558

The model:

namespace App\Models;
use App\Traits\Hashidable;
use App\Models\Scopes\Searchable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Citizenship extends Model
{
    use Hashidable;
    use HasFactory;
    use Searchable;

    protected $fillable = [];

    protected $searchableFields = ['*'];

Currently I have a table for users and it works very well (singular route bind), I also use a table for sessions and there are no problems with the User model. The configurations for Citizenship it is the same as the User model. Now, That's the right behavior, handling routes in sigular, in the RouteServiceprovider??

The user working fine. DeepinScreenshot_Seleccionar área_20230315142519

The Citizenship error:

DeepinScreenshot_Seleccionar área_20230315142546

vinkla commented 1 year ago

Please use a forum such as Laracasts or Discord instead.