Files
citrus/app/Observers/PageObserver.php
T

27 lines
626 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Observers;
use App\Models\Page;
class PageObserver
{
/**
* Handle the Page "saving" event.
*
* Bir sayfa homepage olarak işaretlendiğinde,
* diğer tüm sayfaların homepage işaretini kaldır.
*/
public function saving(Page $page): void
{
// Eğer bu sayfa homepage olarak işaretleniyorsa
if ($page->is_homepage) {
// Diğer tüm sayfaların homepage işaretini kaldır
Page::where('id', '!=', $page->id)
->where('is_homepage', true)
->update(['is_homepage' => false]);
}
}
}