Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Change read to timestamp from boolean #14797

Merged
merged 4 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/Channels/DatabaseChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function send($notifiable, Notification $notification)
'id' => $notification->id,
'type' => get_class($notification),
'data' => $this->getData($notifiable, $notification),
'read' => false,
'read_at' => null,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CreateNotificationsTable extends Migration
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->boolean('read');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Notifications/DatabaseNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DatabaseNotification extends Model
*/
protected $casts = [
'data' => 'array',
'read' => 'boolean',
'read_at' => 'datetime',
];

/**
Expand All @@ -52,7 +52,7 @@ public function notifiable()
*/
public function markAsRead()
{
$this->forceFill(['read' => true])->save();
$this->forceFill(['read_at' => $this->freshTimestamp()])->save();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Notifications/HasDatabaseNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function notifications()
public function unreadNotifications()
{
return $this->morphMany(DatabaseNotification::class, 'notifiable')
->where('read', false)
->whereNull('read_at')
->orderBy('created_at', 'desc');
}
}
2 changes: 1 addition & 1 deletion tests/Notifications/NotificationDatabaseChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testDatabaseChannelCreatesDatabaseRecordWithProperData()
'id' => 1,
'type' => get_class($notification),
'data' => ['invoice_id' => 1],
'read' => false,
'read_at' => null,
]);

$channel = new DatabaseChannel;
Expand Down