Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Hi, Anyone can advice me on the above? Thanks.

Last updated 2 years ago.
0

I would recommend filtering with a where statement, like so:

$items = Model::where('nric', '=', $nric);

Then you may iterate to get the id of each item, like so:

foreach($items as $record){
 $id = $record->id;
 // ....
}
Last updated 2 years ago.
0

jgarifuna said:

I would recommend filtering with a where statement, like so:

$items = Model::where('nric', '=', $nric);

Then you may iterate to get the id of each item, like so:

foreach($items as $record){
$id = $record->id;
// ....
}

I would like to use yr recommendation as it quite easy. But, my Nric is encrypted. So I need to decrypt it in order to find the correct nric..

Last updated 2 years ago.
0

What are you using to encrypt? If it's Laravel's Hash::make function, I believe that is one-way, and can't be decrypted, by design.

If you've used the Crypter, use the decrypt method: http://laravel.com/api/class-Illuminate.Encryption.Encrypter.html

Last updated 2 years ago.
0

AndrewBNZ said:

What are you using to encrypt? If it's Laravel's Hash::make function, I believe that is one-way, and can't be decrypted, by design.

If you've used the Crypter, use the decrypt method: http://laravel.com/api/class-Illuminate.Encryption.Encrypter.html

Nope I am using Crypt::decrypt()

Last updated 2 years ago.
0

chankl78 said:

$nric = 'test';

$items = Model::all()->filter(function($record) use($nric) {
   if($record->nric) == $nric) {
       return $record;
   }
});

This will query all records in the database and will filter it manually in PHP. This is a major performance issue. You're better off using what AndewBNZ suggested.

Last updated 2 years ago.
0

vernard said:

chankl78 said:

$nric = 'test';

$items = Model::all()->filter(function($record) use($nric) {
   if($record->nric) == $nric) {
       return $record;
   }
});

This will query all records in the database and will filter it manually in PHP. This is a major performance issue. You're better off using what AndewBNZ suggested.

hmmm... I have no choice as Nric is encrypted field.

Last updated 2 years ago.
0

chankl78 said:

vernard said:

chankl78 said:

$nric = 'test';

$items = Model::all()->filter(function($record) use($nric) {
   if($record->nric) == $nric) {
       return $record;
   }
});

This will query all records in the database and will filter it manually in PHP. This is a major performance issue. You're better off using what AndewBNZ suggested.

hmmm... I have no choice as Nric is encrypted field. Can you encrypt the value you're testing and then use that in your DB query?

Last updated 2 years ago.
0

thepsion5 said:

chankl78 said:

vernard said:

chankl78 said:

$nric = 'test';

$items = Model::all()->filter(function($record) use($nric) {
   if($record->nric) == $nric) {
       return $record;
   }
});

This will query all records in the database and will filter it manually in PHP. This is a major performance issue. You're better off using what AndewBNZ suggested.

hmmm... I have no choice as Nric is encrypted field. Can you encrypt the value you're testing and then use that in your DB query?

I doubt so as the encryption is dynamic as it is using random string or number.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

chankl78 chankl78 Joined 2 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.