Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 1 year ago.
0
$i = model::where('nric', '=', Crypt::encrypt($value));
Last updated 1 year ago.
0

Thanks for the reply.

I thought the encrypt value is always changing when we save into the database due to the random $IV in the encryption?

Anyway, i did try. The record is still not able to be found.

Last updated 1 year ago.
0
Solution

yes you a right, forgot about that

you can try this though

$nric = 'test';

$items = Model::all()->filter(function($record) use($nric) {
    if(Crypt::decrypt($record->nric) == $nric) {
        return $record;
    }
});
Last updated 1 year ago.
0

Thanks!! It works beautifully. Except that, we do not need to include Crypt::decrypt() for my case as I have already defined it in the model.

Last updated 1 year ago.
0

I've trying to do the same thing, except using pagination...

$nric = 'test';
$items = Model::paginate(10)->filter(function($record) use($nric) {
    if($record->name == $nric) {
        return $record;
    }
});

But it only make the comparison in the pagination '10' records, I understand that could be achieved like this...

$nric = 'test';
$items = Model::get()->filter(function($record) use($nric) {
    if($record->name == $nric) {
        return $record;
    }
})->paginate(10);

Got this: "Call to undefined method Illuminate\Database\Eloquent\Collection::paginate() "

Please, could some one help me to resolve this?

Last updated 1 year ago.
0

I've trying to find encrypted data using pagination but not working.

Model::paginate(10)->filter(function($record) use($request) {
	if (empty($request->input('firstname'))) {
                               return $record;
      } else if (!empty($record->firstname) && !empty($request->input('firstname')) && Crypt::decrypt($record->to) == $request->input('firstname')) {
                      return $record;
                           }
  });

please help me to resolve this

Last updated 6 years ago.
0

You have to use LengthAwarePaginator class. See Laravel docs

Example below.

public function index(Request $request)
    {
        $query = $request->get('search');

        $patients = Patient::all()->filter(function($record) use ($query){
            return (strpos(Crypt::decrypt($record->name),$query) !== false) ? $record : null;
        });

        $count = count($patients);
        $page = (request('page'))?:1;
        $rpp =  3; //(request('perPage'))?:50;
        $offset = $rpp * ($page - 1);
        $paginator = new LengthAwarePaginator($patients->slice($offset,$rpp),$count,$rpp,$page,[
            'path'  => $request->url(),
            'query' => $request->query(),
        ]);
        $patients = $paginator;

        return view('admin.index',compact('patients'));
    }
Last updated 6 years ago.
0

Thanks for reply It is working fine with pagination.

0

Solution it's working but it must be told, it is not the best if not the worst, because it has to get all records first, then decrypt each one and test against your matching conditions. A blind index could be one of the solutions out of many.

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.