Repository URL to install this package:
|
Version:
1.0.0 ▾
|
<?php
namespace Modules\Users\Providers;
use Illuminate\Auth\EloquentUserProvider as BaseEloquentUserProvider;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Support\Str;
class EloquentUserProvider extends BaseEloquentUserProvider implements UserProvider
{
/**
* Retrieve a user by the given credentials.
*
* @param array $credentials
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByCredentials(array $credentials)
{
// First we will add each credential element to the query as a where clause.
// Then we can execute the query and, if we found a user, return it in a
// Eloquent User "model" that will be utilized by the Guard instances.
$query = $this->createModel()->newQuery();
foreach ($credentials as $key => $value) {
if (!Str::contains($key, 'password')) {
$query->where($key, $value);
if (config('users.login_with_username_or_email', false)) {
if ($key == config('users.usernameField', 'username')) {
$query->orWhere(config('users.emailField', 'email'), $value);
} else {
$query->orWhere(config('users.usernameField', 'username'), $value);
}
} else {
$query->where($key, $value);
}
}
}
return $query->first();
}
}