$i = model::where('nric', '=', Crypt::encrypt($value));
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.
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;
}
});
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.
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?
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
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'));
}
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community