Skip to content

Commit

Permalink
✨ sessions support
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Aug 31, 2018
1 parent 6b7b82e commit baddf85
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
],
"require": {
"illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.*",
"php": "~7.0"
"php": "~7.0",
"jenssegers/agent": "^2.6"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion src/Guards/HumbleGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace acidjazz\Humble\Guards;

use Illuminate\Contracts\Auth\Guard;
use Illuminate\Foundation\Auth\User;
// use Illuminate\Foundation\Auth\User;
use App\Models\User;
use Illuminate\Contracts\Auth\Authenticatable;

use acidjazz\Humble\Models\Session;
Expand Down
16 changes: 16 additions & 0 deletions src/Models/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,33 @@

use Illuminate\Database\Eloquent\Model;

use Jenssegers\Agent\Agent;

class Session extends Model {

protected $fillable = ['token','user_id','source','cookie','verified', 'to', 'ip','agent'];
protected $primaryKey = 'token';
public $incrementing = false;
public $appends = ['device'];

public static function hash()
{
return hash('sha256', mt_rand());
}

public function getDeviceAttribute ()
{
$agent = new Agent();
$agent->setUserAgent($this->agent);
return [
'platform' => $agent->platform(),
'browser' => $agent->browser(),
'device' => $agent->device(),
'desktop' => $agent->isDesktop(),
'mobile' => $agent->isMobile(),
];
}

}


2 changes: 1 addition & 1 deletion src/Traits/Humble.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getSession()

public function sessions()
{
return $this->HasMany(Session::class);
return $this->hasMany(Session::class);
}

}

0 comments on commit baddf85

Please sign in to comment.