Skip to content

Commit 9cb715a

Browse files
committed
Configure notification preferences
1 parent 6fb38fb commit 9cb715a

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

config/users.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
'model' => \Backstage\Laravel\Users\Eloquent\Models\UserTraffic::class,
2222
'table' => 'user_traffic',
2323
],
24+
25+
'user_notification_preferences' => [
26+
'model' => \Backstage\Laravel\Users\Eloquent\Models\UserNotificationPreference::class,
27+
'table' => 'user_notification_preferences',
28+
],
2429
],
2530

2631
'events' => [

database/migrations/4_create_user_notification_preferences_table.php.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ return new class extends Migration
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create('user_notification_preferences', function (Blueprint $table) {
14+
Schema::create(config('users.eloquent.user_notification_preferences.table', 'user_notification_preferences'), function (Blueprint $table) {
1515
$table->id();
1616
$table->unsignedBigInteger('user_id');
1717

@@ -27,6 +27,6 @@ return new class extends Migration
2727
*/
2828
public function down(): void
2929
{
30-
Schema::dropIfExists('user_notification_preferences');
30+
Schema::dropIfExists(config('users.eloquent.user_notification_preferences.table', 'user_notification_preferences'));
3131
}
3232
};

src/Eloquent/Concerns/User/HasRelations.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ public function traffic(): HasMany
2323
{
2424
return $this->hasMany(config('users.eloquent.user_traffic.model', UserTraffic::class), 'user_id');
2525
}
26+
27+
public function notificationPreferences(): HasMany
28+
{
29+
return $this->hasMany(config('users.eloquent.user_notification_preferences.model'), 'user_id');
30+
}
2631
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Backstage\Laravel\Users\Eloquent\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Backstage\Laravel\Users\Enums\NotificationType;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
9+
class UserNotificationPreference extends Model
10+
{
11+
protected $fillable = [
12+
'user_id',
13+
'navigation_type',
14+
];
15+
16+
protected $casts = [
17+
'navigation_type' => NotificationType::class,
18+
];
19+
20+
public function user(): BelongsTo
21+
{
22+
return $this->belongsTo(config('users.eloquent.user.model', User::class), 'user_id', 'id');
23+
}
24+
}

src/Enums/NotificationType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Backstage\Laravel\Users\Enums;
4+
5+
enum NotificationType: string
6+
{
7+
case Email = 'email';
8+
case SMS = 'sms';
9+
case InApp = 'in_app';
10+
11+
public function label(): string
12+
{
13+
return match ($this) {
14+
self::Email => __('Email'),
15+
self::SMS => __('SMS'),
16+
self::InApp => __('In App'),
17+
};
18+
}
19+
}

0 commit comments

Comments
 (0)