Skip to content

Commit a60f8f3

Browse files
docs: update README with new features on guarded deletes and navigation badges; add documentation for guarded deletes and navigation badge counts
1 parent 3486263 commit a60f8f3

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Course Hub
22

3-
> **Filament admin authentication:** Filament admins use a dedicated **`admins`** table and **`admin`** guard, separate from student **`users`** / **`web`**. See **[`docs/FILAMENT_ADMIN_AUTH.md`](docs/FILAMENT_ADMIN_AUTH.md)**.
3+
> **Filament Admin Authentication** — Uses a dedicated **`admins`** table and **`admin`** guard, isolated from student **`users`** / **`web`**. See **[`docs/FILAMENT_ADMIN_AUTH.md`](docs/FILAMENT_ADMIN_AUTH.md)**.
4+
> **Guarded Deletes** — Bulk deletes are blocked when records have **active related data** (e.g. published content or enrollments). See **[`docs/DELETE_ACTIVE_RELATIONS.md`](docs/DELETE_ACTIVE_RELATIONS.md)**.
5+
> **Navigation Badges** — Sidebar badges show model counts, cached and updated on create/delete. See **[`docs/FILAMENT_NAVIGATION_BADGE.md`](docs/FILAMENT_NAVIGATION_BADGE.md)**.
46
57
A Laravel-based Learning Management System featuring a **student-facing course experience** and a **Filament-powered admin panel**.
68

docs/DELETE_ACTIVE_RELATIONS.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Guarded Deletes (Filament)
2+
3+
Bulk deletes can break live data (e.g. active courses or enrolled students).
4+
To prevent this, `DeleteBulkAction` uses a **`before()` hook** to validate each selected record.
5+
6+
If a record has **active relations** (published content, enrollments, etc.):
7+
8+
* A danger **notification** is shown
9+
* The action is stopped using **`$action->halt()`**
10+
* Nothing gets deleted
11+
12+
---
13+
14+
## What counts as “active”
15+
16+
* Published courses or lessons
17+
* Courses with enrolled students
18+
* Any related data that shouldn’t be removed
19+
20+
---
21+
22+
## Where it’s implemented
23+
24+
* `CategoriesTable`
25+
* `LevelsTable`
26+
* `CoursesTable`
27+
* `LessonsTable`
28+
* `InstructorsTable`
29+
30+
Path: `app/Filament/Resources/*/Tables/`

docs/FILAMENT_NAVIGATION_BADGE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Filament navigation badge counts
2+
3+
Sidebar resources can show a **numeric badge** next to the nav label (total rows for that resource).
4+
5+
## `HasNavigationBadgeCount` (Filament resources)
6+
7+
**File:** `app/Traits/Filament/HasNavigationBadgeCount.php`
8+
9+
Used on **`Resource`** classes (for example `CategoryResource`). It implements:
10+
11+
* **getNavigationBadge()** — returns a string count from **Cache::rememberForever()**. The cache key is the string `filament:nav-badge:` plus the plural lowercased model class basename (for example `courses`) plus `:count`.
12+
* **getNavigationBadgeColor()** — not read from that cache; it runs a fresh **Model::count()** and maps the result to Filament colors: ≤50 success, ≤100 info, ≤200 warning, above danger.
13+
* **getNavigationBadgeTooltip()** — short static tooltip for the badge.
14+
15+
## Keeping counts fresh: `UpdatesNavigationBadgeCount` (models)
16+
17+
**File:** `app/Traits/Models/UpdatesNavigationBadgeCount.php`
18+
19+
Used on the **same Eloquent models** those resources represent. On **created** / **deleted**, it **Cache::increment** / **Cache::decrement** using a key built as `filament:nav-badge:` plus **getTable()** plus `:count`.
20+
21+
For Laravel’s default table names, that table segment matches the label segment from the resource trait (for example both use `categories`). If you rename a table or use an irregular plural, ensure both traits still target the **same** cache key or badges will drift.
22+
23+
## Where it is used
24+
25+
**Resources:** `CategoryResource`, `CourseResource`, `LevelResource`, `LessonResource`, `InstructorResource`, `UserResource` — each `use HasNavigationBadgeCount`.
26+
27+
**Models:** `Category`, `Course`, `Level`, `Lesson`, `Instructor`, `User` — each `use UpdatesNavigationBadgeCount`.
28+
29+
To add badges for another resource, reuse both traits (resource + model) or adjust the cache key scheme in one place and mirror it in the other.

0 commit comments

Comments
 (0)