Skip to content

Commit

Permalink
Updating the Device model
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Dec 13, 2016
1 parent 9a7d928 commit eb3a6f3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
Expand Up @@ -36,7 +36,6 @@ public function up()
$table->string('model', 64)->index();
$table->string('platform', 64)->index();
$table->string('platform_version', 16)->index();
$table->boolean('is_mobile')->default(false);
$table->timestamp('created_at')->index();
$table->timestamp('updated_at')->index();

Expand Down
10 changes: 5 additions & 5 deletions src/Detectors/DeviceDetector.php
@@ -1,6 +1,7 @@
<?php namespace Arcanedev\LaravelTracker\Detectors;

use Arcanedev\LaravelTracker\Contracts\Detectors\DeviceDetector as DeviceDetectorContract;
use Arcanedev\LaravelTracker\Models\Device;

/**
* Class DeviceDetector
Expand Down Expand Up @@ -45,7 +46,6 @@ public function detect()
return [
'kind' => $this->getDeviceKind(),
'model' => $this->agent->device() ?: '',
'is_mobile' => $this->agent->isMobile(),
];
}

Expand All @@ -56,11 +56,11 @@ public function detect()
*/
public function getDeviceKind()
{
if ($this->isTablet()) return 'Tablet';
if ($this->isPhone()) return 'Phone';
if ($this->isComputer()) return 'Computer';
if ($this->isTablet()) return Device::KIND_TABLET;
if ($this->isPhone()) return Device::KIND_PHONE;
if ($this->isComputer()) return Device::KIND_COMPUTER;

return 'unavailable';
return Device::KIND_UNAVAILABLE;
}

/**
Expand Down
48 changes: 44 additions & 4 deletions src/Models/Device.php
Expand Up @@ -11,12 +11,20 @@
* @property string model
* @property string platform
* @property string platform_version
* @property bool is_mobile
* @property \Carbon\Carbon created_at
* @property \Carbon\Carbon updated_at
*/
class Device extends AbstractModel
{
/* ------------------------------------------------------------------------------------------------
| Constants
| ------------------------------------------------------------------------------------------------
*/
const KIND_COMPUTER = 'computer';
const KIND_PHONE = 'phone';
const KIND_TABLET = 'tablet';
const KIND_UNAVAILABLE = 'unavailable';

/* ------------------------------------------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
Expand All @@ -38,7 +46,6 @@ class Device extends AbstractModel
'model',
'platform',
'platform_version',
'is_mobile',
];

/**
Expand All @@ -47,12 +54,45 @@ class Device extends AbstractModel
* @var array
*/
protected $casts = [
'id' => 'integer',
'is_mobile' => 'boolean',
'id' => 'integer',
];

/* ------------------------------------------------------------------------------------------------
| Relationships
| ------------------------------------------------------------------------------------------------
*/

/* ------------------------------------------------------------------------------------------------
| Check Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Is this a computer?
*
* @return bool
*/
public function isComputer()
{
return $this->kind == static::KIND_COMPUTER;
}

/**
* Is this a phone?
*
* @return bool
*/
public function isPhone()
{
return $this->kind == static::KIND_PHONE;
}

/**
* Is this a tablet?
*
* @return bool
*/
public function isTablet()
{
return $this->kind == static::KIND_TABLET;
}
}

0 comments on commit eb3a6f3

Please sign in to comment.