Completed
Push — master ( 5c2719...0841d5 )
by
unknown
03:14
created

UserModel::findForPassport()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
namespace App\Ship\Parents\Models;
4
5
use Apiato\Core\Abstracts\Models\UserModel as AbstractUserModel;
6
use Apiato\Core\Traits\HashIdTrait;
7
use Apiato\Core\Traits\HasResourceKeyTrait;
8
use Illuminate\Database\Eloquent\SoftDeletes;
9
use Illuminate\Notifications\Notifiable;
10
use Laravel\Passport\HasApiTokens;
11
use Spatie\Permission\Traits\HasRoles;
12
13
/**
14
 * Class UserModel.
15
 *
16
 * @author  Mahmoud Zalt <[email protected]>
17
 */
18
abstract class UserModel extends AbstractUserModel
19
{
20
21
    use Notifiable;
22
    use SoftDeletes;
23
    use HashIdTrait;
24
    use HasRoles;
25
    use HasApiTokens;
26
    use HasResourceKeyTrait;
27
28
    public function findForPassport($identifier)
29
    {
30
        $allowedLoginAttributes = config('authentication-container.login.allowed_login_attributes', ['email' => []]);
31
        $fields = array_keys($allowedLoginAttributes);
32
33
        $builder = $this;
34
35
        foreach ($fields as $field)
36
        {
37
            $builder = $builder->orWhere($field, $identifier);
38
        }
39
40
        $builder = $builder->first();
41
42
        return $builder;
43
    }
44
45
}
46