filter_var($request->input('login'), FILTER_VALIDATE_EMAIL) ? 'email' : 'name'
public function login(Requests $request) {
//假设字段是 email
if ($this->guard()->attempt($request->only('email', 'password'))) {
return $this->sendLoginResponse($request);
}
//假设字段是 mobile
if ($this->guard()->attempt($request->only('mobile', 'password'))) {
return $this->sendLoginResponse($request);
}
//假设字段是 username
if ($this->guard()->attempt($request->only('username', 'password'))) {
return $this->sendLoginResponse($request);
}
return $this->sendFailedLoginResponse($request);
}
public function retrieveByCredentials(array $credentials)
{
if (empty($credentials)) {
return;
}
// 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->orWhere($key, $value);
}
}
return $query->first();
}
class AuthServiceProvider extends ServiceProvider
{
/**
* 注册任何应用认证/授权服务。
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Auth::provider('custom', function ($app, array $config) {
// 返回 Illuminate\Contracts\Auth\UserProvider 实例...
return new CustomUserProvider(new BcryptHasher(), config('auth.providers.custom.model'));
});
}
}
'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], 'custom' => [ 'driver' => 'custom', 'model' => App\Models\User::class, ], ],
'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'custom', ], 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], ],
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有