UserDevice.php 555 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Jenssegers\Agent\Agent;
  5. class UserDevice extends Model
  6. {
  7. protected $fillable = [
  8. 'user_id',
  9. 'ip',
  10. 'user_agent'
  11. ];
  12. public $timestamps = [
  13. 'last_active_at'
  14. ];
  15. public function user()
  16. {
  17. return $this->belongsTo(User::class);
  18. }
  19. public function getUserAgent()
  20. {
  21. if(!$this->user_agent) {
  22. return 'Unknown';
  23. }
  24. $agent = new Agent();
  25. $agent->setUserAgent($this->user_agent);
  26. return $agent;
  27. }
  28. }