Skip to content

Instantly share code, notes, and snippets.

@msacar
Last active January 12, 2020 12:27
Show Gist options
  • Save msacar/068b5a6843b59d4859e2863a9b3764f0 to your computer and use it in GitHub Desktop.
Save msacar/068b5a6843b59d4859e2863a9b3764f0 to your computer and use it in GitHub Desktop.
<?php
namespace App\Models;
use Jenssegers\Mongodb\Eloquent\Model;
class MongoNotification extends Model
{
protected $connection = "mongodb";
protected $table = "notifications";
protected $guarded = [];
/**
* Notifikasyonu okunmuş olarak işaretler.
*
* @return void
*/
public function markAsRead()
{
if (is_null($this->read_at)) {
$this->forceFill([ 'read_at' => $this->freshTimestamp() ])->save();
}
}
/**
* Notifikasyonu okunmamış olarak işaretler.
*
* @return void
*/
public function markAsUnread()
{
if (!is_null($this->read_at)) {
$this->forceFill([ 'read_at' => null ])->save();
}
}
/**
* Notifikasyonun okunmuş olduğunu kontrol eder.
*
* @return bool
*/
public function isRead()
{
return $this->read_at !== null;
}
/**
* Notifikasyonun okunmamış olduğunu kontrol eder
*
* @return bool
*/
public function isUnread()
{
return $this->read_at === null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment