Compare value of a preformatted field with sha1 in eloquent orm

1

I am sending a URL to the mail of a user who should receive it like this:

link

Where 23 is the id of a record in a table, which for practical purposes is not desired at this time, so I convert 23 with sha1 () a string .. so that the URL finally sent is approximately .

http://dominio/registro/fjhjsdfsd9fsdfn4kw8944mfg9rtgmerer

So far so good, the issue is that already back in the system to validate that url I need to contrast it with the original ID (23).

As this is a value that comes from an external environment I would not like to pass the evaluation to eloquent as a MySQL RAW query type:

SELECT * FROM tabla WHERE sha1(id) = "fjhjsdfsd9fsdfn4kw8944mfg9rtgmerer"

But I can not make something like that work in eloquent:

$model = ClaseX::where(sha1("id"),"fjhjsdfs...gmerer")->first();

Obviously sha1 ("id") apparently calculates the value but for the string "id" and not for the id field of the table.

Any ideas to validate the ID that is sent to the mail without having to show it explicitly and not pass a RAW query to Eloquent ???

    
asked by elapez 16.07.2018 в 06:07
source

1 answer

0

As you can see the Hasheado id comes to you as a parameter of the URL, then:

Assuming that the method that this request reaches is called store

public function store($idHaseado){
    $model = ClaseX::where(DB::raw('sha1("id")'),$idHaseado)->first();
}
    
answered by 16.07.2018 в 20:55