Skip to content

Commit

Permalink
use the markAsRead method directly on a collection
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikmanoar authored Apr 6, 2024
1 parent 50061ed commit 5ae7093
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/MessageCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Chatify;

use Illuminate\Database\Eloquent\Collection;

class MessageCollection extends Collection
{
/**
* Mark all notifications as read.
*
* @return void
*/
public function markAsRead()
{
$this->each->markAsRead();
}

/**
* Mark all notifications as unread.
*
* @return void
*/
public function markAsUnread()
{
$this->each->markAsUnread();
}
}
14 changes: 14 additions & 0 deletions src/Models/ChMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Illuminate\Database\Eloquent\Model;
use Chatify\Traits\UUID;
use Chatify\MessageCollection;


class ChMessage extends Model
{
Expand Down Expand Up @@ -94,4 +96,16 @@ public function scopeUnread(Builder $query)
{
return $query->where('seen', 0);
}


/**
* Create a new database notification collection instance.
*
* @param array $models
* @return \Illuminate\Notifications\DatabaseNotificationCollection
*/
public function newCollection(array $models = [])
{
return new MessageCollection($models);
}
}

0 comments on commit 5ae7093

Please sign in to comment.