Welcome Guest, Not a member yet? Register   Sign In
Help searching email in Shield
#11

Can anyone give a code example of finding users by email?
To be honest, I am having a hard time understanding the docs.
I learn better by example.

Thanks
Reply
#12

What do you want to do exactly?
"finding users by email" What do you mean by users? Not a user?

If you want to find and get a User object by an email, you can do it with UserModel::findByCredentials().

PHP Code:
$users auth()->getProvider();
$credentials['email'] = '[email protected]';
$user $users->findByCredentials($credentials); 
Reply
#13

(02-13-2024, 04:15 AM)kenjis Wrote: What do you want to do exactly?
"finding users by email" What do you mean by users? Not a user?

If you want to find and get a User object by an email, you can do it with UserModel::findByCredentials().

PHP Code:
$users auth()->getProvider();
$credentials['email'] = '[email protected]';
$user $users->findByCredentials($credentials); 

Yes, sorry, I did mean just user.
Thanks again for your help
Reply
#14

(This post was last modified: 02-27-2024, 06:53 AM by themban.)

I have successfully implemented Shield for complete user management, I have an admin back-end for adding users, banning, change passwords etc. If I understand your question correctly, you want to search users by email, I have this code on my admin back-end for searching users using: username, first_name, last_name, mobile_number and email (secret) and this code worked for me, you can adapt it to your own environment by deleting the extra fields:


PHP Code:
$search_string '[email protected]';
$UserModel = new \App\Models\UserModel();
$users$UserModel->select('users.*,secret')
->
join('auth_identities''users.id = auth_identities.user_id')
->
groupStart()
->
like('username'$search_string)
->
orLike('first_name'$search_string)
->
orLike('last_name'$search_string)
->
orLike('mobile_number'$search_string)                                    
->orLike('secret'$search_string)
->
groupEnd()
->
where('users.deleted_at IS NULL')
->
orderBy('id''desc')
->
paginate(20); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB