File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 44
55class Config
66{
7+ protected static \Closure $ callback ;
8+
9+ public static function resolvePrunableModelsUsing (\Closure $ callback )
10+ {
11+ static ::$ callback = $ callback ;
12+ }
13+
714 public static function getPrunableModels (): array
815 {
16+ if (isset (static ::$ callback )) {
17+ return call_user_func (static ::$ callback );
18+ }
919 return config ('prunable-fields.models ' , []);
1020 }
1121}
Original file line number Diff line number Diff line change 5656 fn (ModelsFieldsPruned $ e ) => $ e ->count === 1 && $ e ->model === MassPrunableUser::class
5757 );
5858})->with ('user_with_mass_prunable_fields ' );
59+
60+ test ('should allow the prunable models to be overridden at runtime ' , function (MassPrunableUser $ model ) {
61+ \Maize \PrunableFields \Support \Config::resolvePrunableModelsUsing (fn () => [MassPrunableUser::class]);
62+
63+ Event::fake ();
64+
65+ pruneFields ([]);
66+
67+ Event::assertDispatched (
68+ ModelsFieldsPruned::class,
69+ fn (ModelsFieldsPruned $ e ) => $ e ->count === 1 && $ e ->model === MassPrunableUser::class
70+ );
71+
72+ })->with ('user_with_mass_prunable_fields ' );
You can’t perform that action at this time.
0 commit comments