Skip to content

Commit

Permalink
delete keys on page delete
Browse files Browse the repository at this point in the history
  • Loading branch information
nivv committed Jun 19, 2024
1 parent 88bdce4 commit 114957d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,20 @@ protected static function booted()
$item->delete();
});

$modelTypeByMorph = config('fabriq.morph_map.'.Fabriq::getFqnModel('page')) ?? Fabriq::getFqnModel('page');

DB::table('slugs')->where('model_id', $page->id)
->where('model_type', config('fabriq.morph_map.'.Fabriq::getFqnModel('page')) ?? Fabriq::getFqnModel('page'))
->where('model_type', $modelTypeByMorph)
->delete();

DB::table('search_terms')->where('model_id', $page->id)
->where(function ($query) use ($modelTypeByMorph) {
return $query->where('model_type', $modelTypeByMorph)
->orWhere('model_type', Fabriq::getFqnModel('page'));
})
->delete();
});

static::created(function ($page) {
$content = [
'page_title' => $page->name,
Expand Down

0 comments on commit 114957d

Please sign in to comment.