From 95b41dd2853cbff311b5349cc44688bf7d5d1d0a Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Wed, 16 Apr 2025 21:45:50 -0400 Subject: [PATCH] Mention alternative pivot exclusion approach --- docs/advanced-usage/timestamps.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/advanced-usage/timestamps.md b/docs/advanced-usage/timestamps.md index ca0b709fc..d8238691f 100644 --- a/docs/advanced-usage/timestamps.md +++ b/docs/advanced-usage/timestamps.md @@ -5,12 +5,20 @@ weight: 10 ## Excluding Timestamps from JSON -If you want to exclude timestamps from JSON output of role/permission pivots, you can extend the Role and Permission models into your own App namespace and mark the pivot as hidden: +If you want to exclude timestamps from JSON output of role/permission pivots, you can extend the Role and Permission models into your own App and mark the pivot as hidden: ```php protected $hidden = ['pivot']; ``` +Or if you don't want to extend this package's models, another approach could be to add this to your `AppServiceProvider`'s `boot()` method (adapt for Permission model as well, if needed): + +```php +\Spatie\Permission\Models\Role::retrieved(function ($role) { + $role->makeHidden(['pivot']); +}); +``` + ## Adding Timestamps to Pivots If you want to add timestamps to your pivot tables, you can do it with a few steps: