Skip to content

Commit

Permalink
Fixing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Dec 13, 2016
1 parent eb3a6f3 commit f18f3c9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Contracts/Tracker.php
@@ -1,4 +1,5 @@
<?php namespace Arcanedev\LaravelTracker\Contracts;

use Exception;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
Expand Down
6 changes: 2 additions & 4 deletions src/Models/Presenters/SessionPresenter.php
Expand Up @@ -8,7 +8,7 @@
*
* @property string location_name
*
* @property \Arcanedev\LaravelTracker\Models\GeoIp geo_ip
* @property \Arcanedev\LaravelTracker\Models\GeoIp geoip
*/
trait SessionPresenter
{
Expand All @@ -23,8 +23,6 @@ trait SessionPresenter
*/
public function getLocationNameAttribute()
{
return is_null($this->geo_ip)
? 'undefined'
: $this->geo_ip->country_name . ' ' . $this->geo_ip->city;
return $this->hasGeoip() ? $this->geoip->country.' '.$this->geoip->city : 'undefined';
}
}
40 changes: 38 additions & 2 deletions src/Models/Session.php
Expand Up @@ -25,7 +25,7 @@
* @property \Arcanedev\LaravelTracker\Models\Agent agent
* @property \Arcanedev\LaravelTracker\Models\Referer referer
* @property \Arcanedev\LaravelTracker\Models\Cookie cookie
* @property \Arcanedev\LaravelTracker\Models\GeoIp geo_ip
* @property \Arcanedev\LaravelTracker\Models\GeoIp geoip
* @property \Arcanedev\LaravelTracker\Models\Language language
*/
class Session extends AbstractModel
Expand Down Expand Up @@ -150,7 +150,7 @@ public function cookie()
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function geoIp()
public function geoip()
{
return $this->belongsTo(
$this->getModelClass(self::MODEL_GEOIP, GeoIp::class), 'geoip_id'
Expand All @@ -168,4 +168,40 @@ public function language()
$this->getModelClass(self::MODEL_LANGUAGE, Language::class)
);
}

/**
* Session activities relationship.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function activities()
{
return $this->hasMany(
$this->getModelClass(self::MODEL_SESSION_ACTIVITY, SessionActivity::class)
);
}

/* ------------------------------------------------------------------------------------------------
| Check Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Check if the user exists.
*
* @return bool
*/
public function hasUser()
{
return ! is_null($this->user);
}

/**
* Check if the geoip exists.
*
* @return bool
*/
public function hasGeoip()
{
return ! is_null($this->geoip);
}
}

0 comments on commit f18f3c9

Please sign in to comment.