Files
einundzwanzig-portal/app/Observers/LibraryItemObserver.php
HolgerHatGarKeineNode d483c0955a nostr events schedule
2023-02-24 11:54:19 +01:00

67 lines
1.5 KiB
PHP

<?php
namespace App\Observers;
use App\Enums\LibraryItemType;
use App\Models\LibraryItem;
use App\Traits\NostrTrait;
use Exception;
use Illuminate\Support\Facades\Log;
class LibraryItemObserver
{
use NostrTrait;
/**
* Handle the LibraryItem "created" event.
*/
public function created(LibraryItem $libraryItem): void
{
try {
$libraryItem->setStatus('published');
if ($libraryItem->type !== LibraryItemType::MarkdownArticle()) {
if ($libraryItem->whereDoesntHave('libraries',
fn($query) => $query->where('libraries.is_public', false))
->exists()) {
$this->publishOnNostr($libraryItem, $this->getText('LibraryItem'));
}
}
} catch (Exception $e) {
Log::error($e->getMessage());
}
}
/**
* Handle the LibraryItem "updated" event.
*/
public function updated(LibraryItem $libraryItem): void
{
//
}
/**
* Handle the LibraryItem "deleted" event.
*/
public function deleted(LibraryItem $libraryItem): void
{
//
}
/**
* Handle the LibraryItem "restored" event.
*/
public function restored(LibraryItem $libraryItem): void
{
//
}
/**
* Handle the LibraryItem "force deleted" event.
*/
public function forceDeleted(LibraryItem $libraryItem): void
{
//
}
}