Skip to content

Instantly share code, notes, and snippets.

@OzanKurt
Created December 9, 2016 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OzanKurt/5a830dd9fd02ea6b2e27a8124738998e to your computer and use it in GitHub Desktop.
Save OzanKurt/5a830dd9fd02ea6b2e27a8124738998e to your computer and use it in GitHub Desktop.
Why don't we optimize database interactions?
<?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