| Conditions | 2 |
| Paths | 1 |
| Total Lines | 27 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | public function setToken($user_id) |
||
| 28 | { |
||
| 29 | $token = new Model(); |
||
| 30 | |||
| 31 | $ipAddress = new CaptureIpTrait(); |
||
| 32 | $agent = new Agent(); |
||
| 33 | |||
| 34 | $browser = $agent->browser(); |
||
| 35 | $platform = $agent->platform(); |
||
| 36 | |||
| 37 | $token->device = $agent->device(); |
||
| 38 | $token->browser = $browser.'('.$agent->version($browser).')'; |
||
|
|
|||
| 39 | $token->system = $platform.'('.$agent->version($platform).')'; |
||
| 40 | |||
| 41 | $token->user_id = $user_id; |
||
| 42 | $token->last_ip = $ipAddress->getClientIp(); |
||
| 43 | $unique_token = Str::random(60); |
||
| 44 | |||
| 45 | do { |
||
| 46 | $unique_token = Str::random(60); |
||
| 47 | } while (!empty(Model::where('api_token', $unique_token)->first())); |
||
| 48 | |||
| 49 | $token->api_token = $unique_token; |
||
| 50 | $token->login_at = Carbon::now(); |
||
| 51 | $token->save(); |
||
| 52 | |||
| 53 | return $token; |
||
| 54 | } |
||
| 70 |