Skip to content

Commit f139351

Browse files
committed
Login-Link, User Session and some improvements to User Device (#516)
1 parent a6f226c commit f139351

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

resources/lang/en/translations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'created_at' => 'Created at',
1414
'updated_at' => 'Last login',
1515
'active' => 'Active',
16-
'user_type' => 'Model',
16+
'user_type' => 'User Model',
1717
'username' => 'Username',
1818
'slug' => 'Slug',
1919
];

src/Listeners/StoreUserDevice.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use GeoIp2\Database\Reader;
66
use Illuminate\Auth\Events\Login;
77
use Illuminate\Http\Request;
8-
use Illuminate\Support\Str;
98
use Jenssegers\Agent\Agent;
109
use Moox\UserDevice\Models\UserDevice;
1110
use Moox\UserDevice\Services\LocationService;
@@ -42,16 +41,13 @@ public function handle(Login $event)
4241

4342
$title = $platform.' '.$browser.' on '.$os.' in '.($location['city'] ?? '- Unknown').' - '.($location['country'] ?? null);
4443

45-
$slug = Str::slug($title);
46-
4744
$device = UserDevice::updateOrCreate([
4845
'user_id' => $user_id,
4946
'user_type' => get_class($user),
5047
'ip_address' => $ipAddress,
5148
'user_agent' => $userAgent,
5249
], [
5350
'title' => $title,
54-
'slug' => $slug,
5551
'active' => true,
5652
'os' => $os,
5753
'platform' => $platform,

src/Models/UserDevice.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,25 @@ class UserDevice extends Model
1010
protected $table = 'user_devices';
1111

1212
protected $fillable = [
13-
'title', 'slug', 'user_id', 'user_type', 'user_agent',
14-
'platform', 'os', 'browser', 'city', 'country', 'location', 'whitelisted', 'active', 'ip_address',
13+
'title',
14+
'slug',
15+
'user_id',
16+
'user_type',
17+
'user_agent',
18+
'platform',
19+
'os',
20+
'browser',
21+
'city',
22+
'country',
23+
'location',
24+
'whitelisted',
25+
'active',
26+
'ip_address',
27+
];
28+
29+
protected $casts = [
30+
'active' => 'bool',
31+
'whitelisted' => 'bool',
1532
];
1633

1734
/**
@@ -21,9 +38,17 @@ protected static function boot()
2138
{
2239
parent::boot();
2340

24-
// Automatically generate a slug when creating a new device.
25-
static::creating(function ($device) {
26-
$device->slug = Str::slug($device->title);
41+
UserDevice::creating(function ($item) {
42+
$baseSlug = Str::slug($item->title);
43+
$slug = $baseSlug;
44+
$counter = 1;
45+
46+
while (UserDevice::where('slug', $slug)->exists()) {
47+
$slug = "{$baseSlug}-{$counter}";
48+
$counter++;
49+
}
50+
51+
$item->slug = $slug;
2752
});
2853
}
2954

src/Resources/UserDeviceResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class UserDeviceResource extends Resource
2424
{
2525
protected static ?string $model = UserDevice::class;
2626

27-
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
27+
protected static ?string $navigationIcon = 'heroicon-o-computer-desktop';
2828

2929
public static function form(Form $form): Form
3030
{

0 commit comments

Comments
 (0)