Hi, Anyone can advice me on the above? Thanks.
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;
// ....
}
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..
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
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()
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.
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.
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?
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community