Skip to content

Commit 29adba0

Browse files
committed
rename reads table
1 parent 57fb8eb commit 29adba0

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

config/conversations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Elegantly\Conversation\Conversation;
66
use Elegantly\Conversation\ConversationUser;
77
use Elegantly\Conversation\Message;
8-
use Elegantly\Conversation\Read;
8+
use Elegantly\Conversation\MessageRead;
99
use Illuminate\Foundation\Auth\User;
1010

1111
return [
@@ -21,7 +21,7 @@
2121

2222
'model_conversation_user' => ConversationUser::class,
2323

24-
'model_read' => Read::class,
24+
'model_read' => MessageRead::class,
2525

2626
/**
2727
* When a User is deleted, his messages will be deleted

database/migrations/create_reads_table.php.stub renamed to database/migrations/create_message_reads_table.php.stub

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ return new class extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('reads', function (Blueprint $table) {
16+
Schema::create('message_reads', function (Blueprint $table) {
1717
$table->id();
1818
$table->uuid()->unique();
1919

@@ -22,6 +22,8 @@ return new class extends Migration
2222
$table->foreignId('message_id');
2323
$table->foreignId('user_id');
2424

25+
$table->dateTime('read_at')->nullable();
26+
2527
$table->timestamps();
2628

2729
$table->unique(['message_id', 'user_id']);
@@ -35,6 +37,6 @@ return new class extends Migration
3537
*/
3638
public function down()
3739
{
38-
Schema::dropIfExists('reads');
40+
Schema::dropIfExists('message_reads');
3941
}
4042
};

src/ConversationServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function configurePackage(Package $package): void
2323
'create_conversations_table',
2424
'create_messages_table',
2525
'create_conversation_user_table',
26-
'create_reads_table',
26+
'create_message_reads_table',
2727
]);
2828
}
2929
}

src/Message.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use League\CommonMark\MarkdownConverter;
2525

2626
/**
27-
* @template TRead of Read
27+
* @template TMessageRead of MessageRead
2828
* @template TConversation of Conversation
2929
* @template TUser of User
3030
*
@@ -37,7 +37,7 @@
3737
* @property TConversation $conversation
3838
* @property ?int $user_id
3939
* @property ?TUser $user
40-
* @property Collection<int, Read> $reads
40+
* @property Collection<int, MessageRead> $reads
4141
* @property ?ArrayObject<array-key, mixed> $metadata
4242
* @property ?Carbon $created_at
4343
* @property ?Carbon $read_at
@@ -90,7 +90,7 @@ public static function getModelUser(): string
9090
}
9191

9292
/**
93-
* @return class-string<TRead>
93+
* @return class-string<TMessageRead>
9494
*/
9595
public static function getModelRead(): string
9696
{
@@ -114,7 +114,7 @@ public function user(): BelongsTo
114114
}
115115

116116
/**
117-
* @return HasMany<TRead, $this>
117+
* @return HasMany<TMessageRead, $this>
118118
*/
119119
public function reads(): HasMany
120120
{
@@ -139,7 +139,7 @@ public function markAsReadBy(User|int $user, ?Carbon $date = null): static
139139
{
140140
$userId = $user instanceof User ? $user->getKey() : $user;
141141

142-
$read = new Read;
142+
$read = new MessageRead;
143143
$read->user_id = $userId;
144144

145145
if ($date) {

src/Read.php renamed to src/MessageRead.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,24 @@
1616
*
1717
* @property int $id
1818
* @property ?string $origin
19+
* @property ?Carbon $read_at
1920
* @property int $message_id
2021
* @property TMessage $message
2122
* @property int $user_id
2223
* @property TUser $user
2324
* @property Carbon $updated_at
2425
* @property Carbon $created_at
2526
*/
26-
class Read extends Model
27+
class MessageRead extends Model
2728
{
2829
use HasUuid;
2930

3031
protected $guarded = [];
3132

33+
protected $casts = [
34+
'read_at' => 'datetime',
35+
];
36+
3237
/**
3338
* @return class-string<TUser>
3439
*/

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function defineDatabaseMigrations()
4646
'create_conversations_table',
4747
'create_messages_table',
4848
'create_conversation_user_table',
49-
'create_reads_table',
49+
'create_message_reads_table',
5050
] as $migration
5151
) {
5252
(include package_path("database/migrations/{$migration}.php.stub"))->up();

0 commit comments

Comments
 (0)