cartalyst / sentinel

A framework agnostic authentication & authorization system.
BSD 3-Clause "New" or "Revised" License
1.51k stars 238 forks source link

How to search user by it's first name? #518

Closed Nereg closed 4 years ago

Nereg commented 4 years ago

Hello ! I want to search for user by user's first name or any column . First I tryed code like this :

        $credentials = [
            'last_name' => $name
        ];
        $LocalUser = Sentinel::findByCredentials($credentials);

but every time I got just null even when in DB is user with that value of last_name! Please help !

Nereg commented 4 years ago

Any guesses ?

brunogaspar commented 4 years ago

That's to find a User by credentials, it's not designed to perform regular searches on such fields, unless you define those fields to be used as credentials..

You need to either use the User model or the User repository:

Something like

$user = Sentinel::getUserRepository()->createModel()->where('first_name', $firstName)->firstOrFail();

After the createModel() call is all Laravel Eloquent, so you can perform any kind of query with it.