Created
December 9, 2016 06:58
-
-
Save OzanKurt/5a830dd9fd02ea6b2e27a8124738998e to your computer and use it in GitHub Desktop.
Why don't we optimize database interactions?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Illuminate\Notifications; | |
use Illuminate\Database\Eloquent\Collection; | |
class DatabaseNotificationCollection extends Collection | |
{ | |
/** | |
* Mark all notification as read. | |
* | |
* @return void | |
*/ | |
public function markAsRead() | |
{ | |
$ids = $this->pluck('id'); | |
DatabaseNotification::whereIn('id', $ids)->update([ | |
'read_at' => DatabaseNotification::freshTimestamp(), | |
]); | |
} | |
/** | |
* Mark all notification as unread. | |
* | |
* @return void | |
*/ | |
public function markAsUnread() | |
{ | |
$ids = $this->pluck('id'); | |
DatabaseNotification::whereIn('id', $ids)->update([ | |
'read_at' => null, | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment