I need to use the crypt function in a query in laravel. It is a system of saving passwords, and the user and password are encrypted by Crypt::encrypt, I would like to know if it is possible to decrypt in a query to do the search per user too, instead of just the password name.
$passwords = Password::query()
->when($filter_category, function($q) use ($filter_category){
$q->where('category_id', $filter_category);
})
->when($filter_search, function($q) use ($filter_search){
$q->whereHas('category', function ($q) use ($filter_search){
$q->where('category_name', 'LIKE', "%$filter_search%");
});
$q->orWhere('password_name', 'LIKE', "%$filter_search%");
})
->where('user_id', Auth::id())
->paginate(10)
->through(function ($query) {
if ($query->password_login) {
$query->password_login = $this->formatLogin(Crypt::decrypt($query->password_login));
}
return $query;
});
This is the current query, the through() is used for decrypt and show formated, with "exam****@gmail.com" in table, but this dont alter for where work.
I tried to use what was presented earlier. I need to decrypt the login before where to be able to later comcant it for the search.